lucia_lang/objects/
string.rs1use std::{borrow::Borrow, fmt, ops::Deref};
2
3use gc_arena::{Collect, Gc, Mutation};
4
5#[derive(Clone, Copy, Collect, Hash)]
6#[collect(no_drop)]
7pub struct Str<'gc>(pub Gc<'gc, String>);
8
9impl<'gc> Str<'gc> {
10 pub fn new(mc: &Mutation<'gc>, s: String) -> Str<'gc> {
11 Str(Gc::new(mc, s))
12 }
13}
14
15impl<'gc> fmt::Debug for Str<'gc> {
16 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
17 write!(fmt, "Str({})", self)
18 }
19}
20
21impl<'gc> fmt::Display for Str<'gc> {
22 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
23 fmt.write_str(self)
24 }
25}
26
27impl<'gc> Deref for Str<'gc> {
28 type Target = String;
29
30 fn deref(&self) -> &String {
31 &self.0
32 }
33}
34
35impl<'gc> AsRef<String> for Str<'gc> {
36 fn as_ref(&self) -> &String {
37 &self.0
38 }
39}
40
41impl<'gc> Borrow<String> for Str<'gc> {
42 fn borrow(&self) -> &String {
43 &self.0
44 }
45}
46
47impl<'gc, T> PartialEq<T> for Str<'gc>
48where
49 T: ?Sized + AsRef<String>,
50{
51 fn eq(&self, other: &T) -> bool {
52 self.0.as_ref() == other.as_ref()
53 }
54}
55
56impl<'gc> Eq for Str<'gc> {}