hebi/public/object/
string.rs1use super::*;
2use crate::internal::object::{Ptr, Str as OwnedStr};
3use crate::public::{Hebi, Scope};
4
5decl_ref! {
6 struct Str(Ptr<OwnedStr>)
7}
8
9impl_object_ref!(Str, OwnedStr);
10
11impl<'cx> Str<'cx> {
12 pub fn as_str(&self) -> &str {
13 self.inner.as_str()
14 }
15}
16
17impl<'cx> Global<'cx> {
18 pub fn new_string(&self, v: impl ToString) -> Str<'cx> {
19 self.inner.alloc(OwnedStr::owned(v)).bind(self.clone())
20 }
21}
22
23impl<'cx> Scope<'cx> {
24 pub fn new_string(&self, v: impl ToString) -> Str<'cx> {
25 self.global().new_string(v)
26 }
27}
28
29impl Hebi {
30 pub fn new_string(&self, v: impl ToString) -> Str {
31 self.global().new_string(v)
32 }
33}