pub trait Builder {}
pub use buco_derive::Builder;
#[cfg(test)]
mod tests {
use super::*;
use trybuild::TestCases;
#[test]
fn sanity_tests() {
let t = TestCases::new();
t.compile_fail("build_tests/01-builder-enum.rs");
t.compile_fail("build_tests/02-builder-union.rs");
t.pass("build_tests/03-builder-struct.rs");
t.compile_fail("build_tests/04-builder-struct-partial.rs");
t.pass("build_tests/05-builder-struct-complete.rs");
t.compile_fail("build_tests/06-builder-struct-overwrite.rs");
t.pass("build_tests/07-builder-struct-optional.rs");
t.compile_fail("build_tests/08-builder-struct-optional-strict.rs");
}
#[test]
fn test_common_builder() {
#[derive(Builder)]
struct Data {
v1: u8,
v2: String,
v3: f64,
}
let data = Data::builder()
.set_v1(1)
.set_v2("hello".to_string())
.set_v3(1.414)
.build();
assert_eq!(data.v1, 1);
assert_eq!(data.v2, "hello");
assert_eq!(data.v3, 1.414);
}
}