-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements feature to disable any usage of alloc.
- Loading branch information
1 parent
fd86173
commit e2d33f8
Showing
10 changed files
with
224 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[workspace] | ||
members = ["derive_builder", "derive_builder_macro", "derive_builder_core", "derive_builder_no_std_tests"] | ||
members = ["derive_builder", "derive_builder_macro", "derive_builder_core", "derive_builder_no_alloc_tests", "derive_builder_no_std_tests"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "derive_builder_no_alloc_tests" | ||
version = "0.1.0" | ||
authors = ["Micah Weston <micahsweston@gmail.com>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[features] | ||
clippy = ["derive_builder/clippy"] | ||
|
||
[dependencies] | ||
derive_builder = { path = "../derive_builder", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#![no_std] | ||
#![allow(unused, clippy::blacklisted_name)] | ||
|
||
use derive_builder::{self, Builder}; | ||
|
||
#[derive(Debug, Eq, PartialEq)] | ||
pub struct FooError(&'static str); | ||
|
||
impl From<derive_builder::UninitializedFieldError> for FooError { | ||
fn from(err: derive_builder::UninitializedFieldError) -> Self { | ||
Self(err.field_name()) | ||
} | ||
} | ||
|
||
#[derive(Builder)] | ||
#[builder(no_std, build_fn(error = "FooError"))] | ||
pub struct Foo { | ||
pub bar: i32, | ||
} | ||
|
||
#[derive(Builder)] | ||
#[builder(no_std, build_fn(validation_error = false))] | ||
pub struct Fee { | ||
pub bar: i32, | ||
} | ||
|
||
pub fn build_foo_ok() -> Foo { | ||
FooBuilder::default().bar(42).build().unwrap() | ||
} | ||
|
||
pub fn build_foo_err() -> Option<FooError> { | ||
let foo = FooBuilder::default().build(); | ||
foo.err() | ||
} | ||
|
||
pub fn build_fee_ok() -> Foo { | ||
FooBuilder::default().bar(42).build().unwrap() | ||
} | ||
|
||
pub fn build_fee_err() -> Option<FeeBuilderError> { | ||
let fee = FeeBuilder::default().build(); | ||
fee.err() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_foo_builder_ok() { | ||
assert_eq!(build_foo_ok().bar, 42); | ||
} | ||
|
||
#[test] | ||
fn test_foo_builder_err() { | ||
assert_eq!(build_foo_err(), Some(FooError("bar"))); | ||
} | ||
|
||
#[test] | ||
fn test_fee_builder_ok() { | ||
assert_eq!(build_fee_ok().bar, 42); | ||
} | ||
|
||
#[test] | ||
fn test_fee_builder_err() { | ||
assert!(matches!( | ||
build_fee_err(), | ||
Some(FeeBuilderError::UninitializedField("bar")) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters