Closed red1bluelost closed 9 months ago
You should be able to avoid the usage of String
here by providing a custom error yourself - did that still result in generated code that used String
?
You should be able to avoid the usage of
String
here by providing a custom error yourself - did that still result in generated code that usedString
?
I did try custom errors and it is a good way to not import any alloc code but it does not prevent linking alloc
. Since extern crate alloc
still exists in 'derive_builder/src/lib.rs', it will try to link with a global_allocator
which is mainly what I want to avoid.
Thanks for the explanation! I am onboard with making alloc
optional based on that, and will reexamine your PR with this in mind.
Looks like this didn't get auto-closed by the relevant commit; the changes are in v0.13.0
When using the library with
no_std
,derive_builder
's dependency onalloc
forces the user to provide aglobal_allocator
even if they don't use anything that would require allocations (i.e.*BuilderError::ValidationError(String)
). It would be helpful for someno_std
libraries to have a way to disable this dependency onalloc
.I made a PR as a possible solution for this. It provides a feature
alloc
that controls whetherextern crate alloc
is included during nostd
feature. It also provides abuild_fn
fieldvalidation_error
that will disable the generation of*BuilderError::ValidationError(String)
so that is never referenced. https://github.com/colin-kiegel/rust-derive-builder/pull/302