pub fn with_buffer<const BUF: usize, O>(
body: impl FnOnce(&DefaultAllocator<'_, BUF>) -> O,
) -> OExpand description
Same as default() but allows for specifying a default static buffer size
other than DEFAULT_ARRAY_BUFFER.
See default() for more information.
ยงExamples
use musli::alloc::{AllocError, Vec};
musli::alloc::with_buffer::<128, _>(|alloc| {
let mut a = Vec::new_in(alloc);
let mut b = Vec::new_in(alloc);
b.extend_from_slice(b"He11o")?;
a.extend_from_slice(b.as_slice())?;
assert_eq!(a.as_slice(), b"He11o");
assert_eq!(a.len(), 5);
a.extend_from_slice(b" W0rld")?;
assert_eq!(a.as_slice(), b"He11o W0rld");
assert_eq!(a.len(), 11);
let mut c = Vec::new_in(alloc);
c.extend_from_slice(b"!")?;
a.extend_from_slice(c.as_slice())?;
assert_eq!(a.as_slice(), b"He11o W0rld!");
assert_eq!(a.len(), 12);
Ok::<_, AllocError>(())
});