Skip to content

Commit

Permalink
Implement Debug for InternedStr (#1760)
Browse files Browse the repository at this point in the history
commit-id:919c7f28

---

**Stack**:
- #1749
- #1748
- #1745
- #1747
- #1760⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
  • Loading branch information
maciektr committed Nov 25, 2024
1 parent 45c40ff commit ae6869e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/cairo-lang-macro/src/types/token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::CONTEXT;
use bumpalo::Bump;
use std::fmt::Display;
use std::fmt::{Debug, Display, Write};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -132,13 +132,21 @@ impl Token {
/// and a guard which keeps the buffer alive.
/// This way we do not need to allocate a new string,
/// but also do not need to worry about the lifetime of the string.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct InternedStr {
ptr: *const str,
// Holding a rc to the underlying buffer, so that ptr will always point to valid memory.
_bump: Rc<BumpWrap>,
}

impl Debug for InternedStr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_char('"')?;
f.write_str(self.as_ref())?;
f.write_char('"')
}
}

impl InternedStr {
#[allow(private_interfaces)]
#[doc(hidden)]
Expand Down

0 comments on commit ae6869e

Please sign in to comment.