diff --git a/crates/oxc_allocator/src/lib.rs b/crates/oxc_allocator/src/lib.rs index dd27f411c..da6f1c14b 100644 --- a/crates/oxc_allocator/src/lib.rs +++ b/crates/oxc_allocator/src/lib.rs @@ -1,4 +1,4 @@ -use std::ops::Deref; +use std::{convert::From, ops::Deref}; mod arena; @@ -10,6 +10,12 @@ pub struct Allocator { bump: Bump, } +impl From for Allocator { + fn from(bump: Bump) -> Self { + Self { bump } + } +} + impl Deref for Allocator { type Target = Bump; @@ -17,3 +23,21 @@ impl Deref for Allocator { &self.bump } } + +#[cfg(test)] +mod test { + use std::ops::Deref; + + use crate::Allocator; + use bumpalo::Bump; + + #[test] + fn test_api() { + let bump = Bump::new(); + let allocator: Allocator = bump.into(); + #[allow(clippy::explicit_deref_methods)] + { + _ = allocator.deref(); + } + } +}