Skip to content
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
31 changes: 17 additions & 14 deletions byteyarn/src/boxed.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::alloc::Layout;
use std::cmp::Ordering;
use std::fmt;
use std::hash::Hash;
use std::hash::Hasher;
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use std::ptr::NonNull;
use std::slice;
use std::str;
use std::str::Utf8Error;
use ::alloc::boxed::Box;
use ::alloc::string::String;
use ::alloc::vec::Vec;
use core::alloc::Layout;
use core::cmp::Ordering;
use core::fmt;
use core::hash::Hash;
use core::hash::Hasher;
use core::marker::PhantomData;
use core::mem;
use core::ops::Deref;
use core::ptr::NonNull;
use core::slice;
use core::str;
use core::str::Utf8Error;

use crate::raw::RawYarn;
use crate::Utf8Chunks;
Expand Down Expand Up @@ -328,11 +331,11 @@ where
let layout = buf_trait::layout_of(self.as_slice());
let ptr = match layout.size() {
0 => NonNull::<Buf::Element>::dangling().as_ptr() as *mut u8,
_ => std::alloc::alloc(layout),
_ => alloc::alloc::alloc(layout),
};

if ptr.is_null() {
std::alloc::handle_alloc_error(layout);
alloc::alloc::handle_alloc_error(layout);
}

let raw = self.into_raw();
Expand Down
9 changes: 6 additions & 3 deletions byteyarn/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::borrow::Borrow;
use std::fmt;
use std::str::Utf8Error;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::borrow::Borrow;
use core::fmt;
use core::str::Utf8Error;

use crate::YarnBox;
use crate::YarnRef;
Expand Down
7 changes: 5 additions & 2 deletions byteyarn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@
//! ```

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

extern crate alloc;

#[cfg(doc)]
use std::borrow::Cow;
use alloc::borrow::Cow;

mod boxed;
mod convert;
Expand All @@ -87,7 +90,7 @@ pub use buf_trait::Buf;
// Macro stuff.
#[doc(hidden)]
pub mod m {
pub extern crate std;
pub extern crate core as std;
}

/// An optimized Unicode string.
Expand Down
32 changes: 17 additions & 15 deletions byteyarn/src/raw.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::alloc;
use std::fmt;
use std::fmt::Write;
use std::mem;
use std::mem::ManuallyDrop;
use std::mem::MaybeUninit;
use std::num::NonZeroUsize;
use std::ptr;
use std::slice;
use ::alloc::boxed::Box;
use ::alloc::vec::Vec;
use core::alloc;
use core::fmt;
use core::fmt::Write;
use core::mem;
use core::mem::ManuallyDrop;
use core::mem::MaybeUninit;
use core::num::NonZeroUsize;
use core::ptr;
use core::slice;

/// The core implementation of yarns.
///
Expand Down Expand Up @@ -237,7 +239,7 @@ impl RawYarn {
}

debug_assert!(layout.size() > 0);
alloc::dealloc(self.ptr as *mut u8, layout)
::alloc::alloc::dealloc(self.ptr as *mut u8, layout)
}

/// Returns a pointer into the data for this raw yarn.
Expand Down Expand Up @@ -326,7 +328,7 @@ impl RawYarn {
// SAFETY: This is a precondition for this function.
// This allows the compiler to assume len <= Self::SSO_LEN for the rest
// of the function body.
std::hint::unreachable_unchecked();
core::hint::unreachable_unchecked();
}

let tagged_len = (len as u8) | Self::SMALL << Self::SHIFT8;
Expand Down Expand Up @@ -579,9 +581,9 @@ impl AlignedBox {
layout: alloc::Layout,
slices: impl IntoIterator<Item = &'a [u8]>,
) -> Self {
let mut ptr = alloc::alloc(layout);
let mut ptr = ::alloc::alloc::alloc(layout);
if ptr.is_null() {
alloc::handle_alloc_error(layout);
::alloc::alloc::handle_alloc_error(layout);
}

for slice in slices {
Expand Down Expand Up @@ -626,9 +628,9 @@ impl Drop for AlignedBox {
ManuallyDrop::new(mem::replace(&mut self.data, [].into())).as_mut_ptr();

unsafe {
alloc::dealloc(
::alloc::alloc::dealloc(
ptr,
alloc::Layout::from_size_align_unchecked(len, self.align),
::alloc::alloc::Layout::from_size_align_unchecked(len, self.align),
)
}
}
Expand Down
23 changes: 13 additions & 10 deletions byteyarn/src/reffed.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::cmp::Ordering;
use std::fmt;
use std::fmt::Write;
use std::hash::Hash;
use std::hash::Hasher;
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use std::str;
use std::str::Utf8Error;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::cmp::Ordering;
use core::fmt;
use core::fmt::Write;
use core::hash::Hash;
use core::hash::Hasher;
use core::marker::PhantomData;
use core::mem;
use core::ops::Deref;
use core::str;
use core::str::Utf8Error;

use crate::raw::RawYarn;
use crate::Utf8Chunks;
Expand Down
2 changes: 1 addition & 1 deletion byteyarn/src/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! UTF-8 utilities not provided by the standard library.

use std::str;
use core::str;

#[cfg(doc)]
use crate::*;
Expand Down