Merge pull request #49 from alexcrichton/term

Use the same api for imp::Term as for Term
This commit is contained in:
Alex Crichton 2018-01-06 13:10:58 -06:00 committed by GitHub
commit f2c71050ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 19 deletions

View File

@ -242,11 +242,11 @@ pub struct Term(imp::Term);
impl Term {
pub fn intern(string: &str) -> Term {
Term(string.into())
Term(imp::Term::intern(string))
}
pub fn as_str(&self) -> &str {
&self.0
self.0.as_str()
}
}

View File

@ -7,7 +7,6 @@ use std::collections::HashMap;
use std::fmt;
use std::iter;
use std::marker::PhantomData;
use std::ops;
use std::rc::Rc;
use std::str::FromStr;
use std::vec;
@ -398,19 +397,15 @@ pub struct Term {
thread_local!(static SYMBOLS: RefCell<Interner> = RefCell::new(Interner::new()));
impl<'a> From<&'a str> for Term {
fn from(string: &'a str) -> Term {
impl Term {
pub fn intern(string: &str) -> Term {
Term {
intern: SYMBOLS.with(|s| s.borrow_mut().intern(string)),
not_send_sync: PhantomData,
}
}
}
impl ops::Deref for Term {
type Target = str;
fn deref(&self) -> &str {
pub fn as_str(&self) -> &str {
SYMBOLS.with(|interner| {
let interner = interner.borrow();
let s = interner.get(self.intern);
@ -423,7 +418,7 @@ impl ops::Deref for Term {
impl fmt::Debug for Term {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Term").field(&&**self).finish()
f.debug_tuple("Term").field(&self.as_str()).finish()
}
}

View File

@ -1,7 +1,6 @@
use std::ascii;
use std::fmt;
use std::iter;
use std::ops;
use std::str::FromStr;
use proc_macro;
@ -269,16 +268,12 @@ impl fmt::Debug for Span {
#[derive(Copy, Clone)]
pub struct Term(proc_macro::Term);
impl<'a> From<&'a str> for Term {
fn from(string: &'a str) -> Term {
impl Term {
pub fn intern(string: &str) -> Term {
Term(proc_macro::Term::intern(string))
}
}
impl ops::Deref for Term {
type Target = str;
fn deref(&self) -> &str {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}