Skip to content

Commit

Permalink
no_std compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0x64 committed Apr 24, 2020
1 parent 53c2e79 commit a010eb4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::ToTokens;

use std::iter;
use core::iter;

use proc_macro2::{TokenStream, TokenTree};

Expand Down
6 changes: 4 additions & 2 deletions src/ident_fragment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use proc_macro2::{Ident, Span};
use std::fmt;
use core::fmt;

use alloc::string::ToString;

/// Specialized formatting trait used by `format_ident!`.
///
Expand Down Expand Up @@ -68,5 +70,5 @@ macro_rules! ident_fragment_display {
}
}

ident_fragment_display!(bool, str, String);
ident_fragment_display!(bool, str, alloc::string::String);
ident_fragment_display!(u8, u16, u32, u64, u128, usize);
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
//! }
//! };
//! ```
#![no_std]

#![forbid(unsafe_code)]

Expand All @@ -83,6 +84,9 @@
))]
extern crate proc_macro;

#[macro_use]
extern crate alloc;

mod ext;
mod format;
mod ident_fragment;
Expand Down
10 changes: 5 additions & 5 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{IdentFragment, ToTokens, TokenStreamExt};
use std::fmt;
use std::ops::BitOr;
use core::fmt;
use core::ops::BitOr;

pub use proc_macro2::*;

Expand Down Expand Up @@ -45,8 +45,8 @@ pub mod ext {
use super::RepInterp;
use super::{HasIterator as HasIter, ThereIsNoIteratorInRepetition as DoesNotHaveIter};
use crate::ToTokens;
use std::collections::btree_set::{self, BTreeSet};
use std::slice;
use alloc::collections::btree_set::{self, BTreeSet};
use core::slice;

/// Extension trait providing the `quote_into_iter` method on iterators.
pub trait RepIteratorExt: Iterator + Sized {
Expand Down Expand Up @@ -107,7 +107,7 @@ pub mod ext {
}
}

impl<'q, T: 'q> RepAsIteratorExt<'q> for Vec<T> {
impl<'q, T: 'q> RepAsIteratorExt<'q> for alloc::vec::Vec<T> {
type Iter = slice::Iter<'q, T>;

fn quote_into_iter(&'q self) -> (Self::Iter, HasIter) {
Expand Down
12 changes: 6 additions & 6 deletions src/to_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::TokenStreamExt;

use std::borrow::Cow;
use std::iter;
use std::rc::Rc;
use alloc::borrow::Cow;
use core::iter;
use alloc::rc::Rc;

use proc_macro2::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};

Expand Down Expand Up @@ -88,13 +88,13 @@ impl<'a, T: ?Sized + ToTokens> ToTokens for &'a mut T {
}
}

impl<'a, T: ?Sized + ToOwned + ToTokens> ToTokens for Cow<'a, T> {
impl<'a, T: ?Sized + alloc::borrow::ToOwned + ToTokens> ToTokens for Cow<'a, T> {
fn to_tokens(&self, tokens: &mut TokenStream) {
(**self).to_tokens(tokens);
}
}

impl<T: ?Sized + ToTokens> ToTokens for Box<T> {
impl<T: ?Sized + ToTokens> ToTokens for alloc::boxed::Box<T> {
fn to_tokens(&self, tokens: &mut TokenStream) {
(**self).to_tokens(tokens);
}
Expand All @@ -120,7 +120,7 @@ impl ToTokens for str {
}
}

impl ToTokens for String {
impl ToTokens for alloc::string::String {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.as_str().to_tokens(tokens);
}
Expand Down

0 comments on commit a010eb4

Please sign in to comment.