Skip to content

replace std by core and alloc #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
//!
//! See the [`LinearMap`](struct.LinearMap.html) type for details.

#![no_std]
#![deny(missing_docs)]

extern crate alloc;

// Optional Serde support
#[cfg(feature = "serde_impl")]
pub mod serde;
pub mod set;

use std::borrow::Borrow;
use std::fmt::{self, Debug};
use std::iter;
use std::mem;
use std::ops;
use std::slice;
use std::vec;
use alloc::vec::{self, Vec};
use core::borrow::Borrow;
use core::fmt::{self, Debug};
use core::iter;
use core::mem;
use core::ops;
use core::slice;

use self::Entry::{Occupied, Vacant};

Expand Down Expand Up @@ -79,7 +82,9 @@ pub struct LinearMap<K, V> {
impl<K: Eq, V> LinearMap<K, V> {
/// Creates an empty map. This method does not allocate.
pub fn new() -> Self {
LinearMap { storage: vec![] }
LinearMap {
storage: Vec::new(),
}
}

/// Creates an empty map with the given initial capacity.
Expand Down
4 changes: 2 additions & 2 deletions src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use self::serde::de::{Error, MapAccess, SeqAccess, Visitor};
use self::serde::ser::{SerializeMap, SerializeSeq};
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};

use std::fmt;
use std::marker::PhantomData;
use core::fmt;
use core::marker::PhantomData;

impl<K, V> Serialize for LinearMap<K, V>
where
Expand Down
13 changes: 7 additions & 6 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//!
//! See the [`LinearSet`](struct.LinearSet.html) type for details.

use std::borrow::Borrow;
use std::fmt;
use std::iter::{Chain, FromIterator};
use std::ops::{BitAnd, BitOr, BitXor, Sub};
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::fmt;
use core::iter::{Chain, FromIterator};
use core::ops::{BitAnd, BitOr, BitXor, Sub};

use super::{Keys, LinearMap};

Expand Down Expand Up @@ -574,13 +575,13 @@ where

impl<K: Eq> From<LinearSet<K>> for Vec<K> {
fn from(other: LinearSet<K>) -> Self {
unsafe { std::mem::transmute(other) }
unsafe { core::mem::transmute(other) }
}
}

impl<K: Eq> From<Vec<K>> for LinearSet<K> {
fn from(other: Vec<K>) -> Self {
unsafe { std::mem::transmute(other) }
unsafe { core::mem::transmute(other) }
}
}

Expand Down