Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::borrow::Cow;
- pub struct SmbClient<'a> {
- //ctx: *mut SMBCCTX,
- #[allow(dead_code)]
- auth_fn: &'a for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>),
- }
- impl<'a> SmbClient<'a> {
- pub fn new<F>(auth_fn: &'a F) -> Option<SmbClient<'a>>
- where F: for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) {
- let smbc = SmbClient {
- //ctx: ptr::null_mut(),
- auth_fn: auth_fn,
- };
- Some(smbc)
- }
- }
- //type AuthType<'a> = for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>) + 'a;
- pub struct Builder<'a,F:for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>)> {
- _auth:F,
- auth_ref: &'a F,
- }
- pub fn new_builder<'a>(username: &'a str, password: &'a str, domain: &'a str) ->
- Builder<'a,impl for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>)>
- {
- let (auth,auth_ref) = unsafe{
- let func=move |_host: &str, _share: &str| {
- (Cow::from(domain), Cow::from(username), Cow::from(password))
- };
- let func_ref= {
- &*(&func as *const _)
- };
- (func,func_ref)
- };
- Builder {
- _auth:auth,
- auth_ref,
- }
- }
- impl <'a,F:for<'b> Fn(&'b str, &'b str) -> (Cow<'a, str>, Cow<'a, str>, Cow<'a, str>)>
- Builder<'a,F>
- {
- fn build(&self) -> Connector<'a>{
- let client=SmbClient::new(self.auth_ref);
- Connector{
- client
- }
- }
- }
- struct Connector<'x>
- {
- client: Option<SmbClient<'x>>,
- }
- fn main()
- {
- let builder=new_builder("a","b","c");
- let c=builder.build();
- println!("Good");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement