Skip to content

Commit

Permalink
officially support #![no_std] #41 -- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-kiegel committed Feb 20, 2017
1 parent 32a6437 commit 0fc036d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- use full path for result #39
- support `#[deny(missing_docs)]` #37
- support `#![no_std]` #41

## [0.3.0] - 2017-02-05

Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,18 @@ fn builder_for_struct(ast: syn::MacroInput) -> quote::Tokens {
SetterPattern::Mutable => quote!(&self),
SetterPattern::Immutable => quote!(&self),
};
let initializers_ref = &initializers;
quote!(
#[cfg(not(no_std))]
#builder_vis fn build(#ref_self) -> ::std::result::Result<#struct_name #ty_generics, ::std::string::String> {
Ok(#struct_name {
#(#initializers)*
#(#initializers_ref)*
})
}
#[cfg(no_std)]
#builder_vis fn build(#ref_self) -> ::core::result::Result<#struct_name #ty_generics, ::collections::string::String> {
Ok(#struct_name {
#(#initializers_ref)*
})
}
)
Expand Down
20 changes: 20 additions & 0 deletions tests/no_std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![no_std]
#![feature(collections)]
#![allow(dead_code)]

#[macro_use]
extern crate derive_builder;
extern crate collections;

#[derive(Builder)]
struct IgnoreEmptyStruct {}

#[test]
fn empty_struct() {
// this is just a compile-test - no run time checks required.
}

#[test]
fn write_docs() {
unimplemented!()
}

0 comments on commit 0fc036d

Please sign in to comment.