Skip to content

Commit f2c7105

Browse files
authored
Merge pull request #49 from alexcrichton/term
Use the same api for imp::Term as for Term
2 parents c2f9c6a + 10effeb commit f2c7105

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ pub struct Term(imp::Term);
242242

243243
impl Term {
244244
pub fn intern(string: &str) -> Term {
245-
Term(string.into())
245+
Term(imp::Term::intern(string))
246246
}
247247

248248
pub fn as_str(&self) -> &str {
249-
&self.0
249+
self.0.as_str()
250250
}
251251
}
252252

src/stable.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::collections::HashMap;
77
use std::fmt;
88
use std::iter;
99
use std::marker::PhantomData;
10-
use std::ops;
1110
use std::rc::Rc;
1211
use std::str::FromStr;
1312
use std::vec;
@@ -398,19 +397,15 @@ pub struct Term {
398397

399398
thread_local!(static SYMBOLS: RefCell<Interner> = RefCell::new(Interner::new()));
400399

401-
impl<'a> From<&'a str> for Term {
402-
fn from(string: &'a str) -> Term {
400+
impl Term {
401+
pub fn intern(string: &str) -> Term {
403402
Term {
404403
intern: SYMBOLS.with(|s| s.borrow_mut().intern(string)),
405404
not_send_sync: PhantomData,
406405
}
407406
}
408-
}
409-
410-
impl ops::Deref for Term {
411-
type Target = str;
412407

413-
fn deref(&self) -> &str {
408+
pub fn as_str(&self) -> &str {
414409
SYMBOLS.with(|interner| {
415410
let interner = interner.borrow();
416411
let s = interner.get(self.intern);
@@ -423,7 +418,7 @@ impl ops::Deref for Term {
423418

424419
impl fmt::Debug for Term {
425420
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
426-
f.debug_tuple("Term").field(&&**self).finish()
421+
f.debug_tuple("Term").field(&self.as_str()).finish()
427422
}
428423
}
429424

src/unstable.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::ascii;
22
use std::fmt;
33
use std::iter;
4-
use std::ops;
54
use std::str::FromStr;
65

76
use proc_macro;
@@ -269,16 +268,12 @@ impl fmt::Debug for Span {
269268
#[derive(Copy, Clone)]
270269
pub struct Term(proc_macro::Term);
271270

272-
impl<'a> From<&'a str> for Term {
273-
fn from(string: &'a str) -> Term {
271+
impl Term {
272+
pub fn intern(string: &str) -> Term {
274273
Term(proc_macro::Term::intern(string))
275274
}
276-
}
277-
278-
impl ops::Deref for Term {
279-
type Target = str;
280275

281-
fn deref(&self) -> &str {
276+
pub fn as_str(&self) -> &str {
282277
self.0.as_str()
283278
}
284279
}

0 commit comments

Comments
 (0)