abin/implementation/
factory_new.rs1use std::marker::PhantomData;
2
3use crate::{
4 AnyRc, Bin, BinBuilder, BinFactory, BooToOwned, BuilderCfg, DefaultBinBuilder, IntoUnSyncView,
5 RcBin, SBin,
6};
7
8pub struct NewBin {
16 _phantom: PhantomData<()>,
17}
18
19impl NewBin {
20 pub fn builder<'a>() -> impl BinBuilder<'a, T = Bin> {
22 DefaultBinBuilder::<NewBin, BinBuilderCfg>::new()
23 }
24}
25
26impl BooToOwned<[u8], Bin> for NewBin {
27 fn convert_to_owned(borrowed: &[u8]) -> Bin {
28 Self::copy_from_slice(borrowed)
29 }
30}
31
32struct BinBuilderCfg;
33
34impl BuilderCfg<Bin> for BinBuilderCfg {
35 fn convert_from_sbin_to_t(sbin: SBin) -> Bin {
36 sbin.un_sync()
37 }
38
39 fn vec_excess_capacity() -> usize {
40 RcBin::overhead_bytes()
41 }
42}