Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring: re-export custom derive with additional items (WIP) #94

Closed
wants to merge 9 commits into from
11 changes: 11 additions & 0 deletions derive_builder_core/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ impl Bindings {
Bindings::NoStd => ":: collections :: string :: String",
})
}

/// TryInto trait. Once `TryFrom` stabilizes, this should be removed and
/// `derive_builder::export` should export `core::convert::TryInto` directly.
pub fn try_into_trait(&self) -> RawTokens<&'static str> {
RawTokens(match *self {
Bindings::Std => ":: std :: convert :: TryInto",
Bindings::NoStd => ":: core :: convert :: TryInto",
})
}
}

#[test]
fn std() {
let b = Bindings::Std;

assert_eq!(b.string_ty().to_tokens(), quote!(::std::string::String));
assert_eq!(b.try_into_trait().to_tokens(), quote!(::std::convert::TryInto));
}

#[test]
Expand All @@ -38,4 +48,5 @@ fn no_std() {

assert_eq!(b.string_ty().to_tokens(),
quote!(::collections::string::String));
assert_eq!(b.try_into_trait().to_tokens(), quote!(::core::convert::TryInto));
}
7 changes: 4 additions & 3 deletions derive_builder_core/src/setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl<'a> ToTokens for Setter<'a> {
}));

if self.try_setter {
let try_ty_params = quote!(<VALUE: ::derive_builder::export::TryInto<#ty>>);
let try_into_trait = self.bindings.try_into_trait();
let try_ty_params = quote!(<VALUE: #try_into_trait<#ty>>);
let try_ident = syn::Ident::new(format!("try_{}", ident));

tokens.append(quote!(
Expand Down Expand Up @@ -264,7 +265,7 @@ mod tests {
}

#[some_attr]
pub fn try_foo<VALUE: ::derive_builder::export::TryInto<Foo>>(&mut self, value: VALUE)
pub fn try_foo<VALUE: ::std::convert::TryInto<Foo>>(&mut self, value: VALUE)
-> ::derive_builder::export::Result<&mut Self, VALUE::Error> {
let converted : Foo = value.try_into()?;
let mut new = self;
Expand Down Expand Up @@ -325,7 +326,7 @@ mod tests {
new
}

pub fn try_foo<VALUE: ::derive_builder::export::TryInto<Foo>>(&mut self, value: VALUE)
pub fn try_foo<VALUE: ::std::convert::TryInto<Foo>>(&mut self, value: VALUE)
-> ::derive_builder::export::Result<&mut Self, VALUE::Error> {
let converted : Foo = value.try_into()?;
let mut new = self;
Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/no_std

This file was deleted.