Skip to content

Commit c08778d

Browse files
authored
refactor: prepare for no-std (#39)
1 parent 8e17a00 commit c08778d

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/ffi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(non_camel_case_types)]
2-
use std::ffi::{c_char, c_uint};
2+
use core::ffi::{c_char, c_uint};
33

44
#[repr(C)]
55
pub struct ada_url {
@@ -16,8 +16,8 @@ pub struct ada_string {
1616
impl ada_string {
1717
pub fn as_str(&self) -> &'static str {
1818
unsafe {
19-
let slice = std::slice::from_raw_parts(self.data.cast(), self.length);
20-
std::str::from_utf8_unchecked(slice)
19+
let slice = core::slice::from_raw_parts(self.data.cast(), self.length);
20+
core::str::from_utf8_unchecked(slice)
2121
}
2222
}
2323
}
@@ -31,8 +31,8 @@ pub struct ada_owned_string {
3131
impl AsRef<str> for ada_owned_string {
3232
fn as_ref(&self) -> &str {
3333
unsafe {
34-
let slice = std::slice::from_raw_parts(self.data.cast(), self.length);
35-
std::str::from_utf8_unchecked(slice)
34+
let slice = core::slice::from_raw_parts(self.data.cast(), self.length);
35+
core::str::from_utf8_unchecked(slice)
3636
}
3737
}
3838
}

src/idna.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl Idna {
1818
pub fn unicode(input: &str) -> &str {
1919
unsafe {
2020
let out = ffi::ada_idna_to_unicode(input.as_ptr().cast(), input.len());
21-
let slice = std::slice::from_raw_parts(out.data.cast(), out.length);
22-
std::str::from_utf8_unchecked(slice)
21+
let slice = core::slice::from_raw_parts(out.data.cast(), out.length);
22+
core::str::from_utf8_unchecked(slice)
2323
}
2424
}
2525

@@ -35,8 +35,8 @@ impl Idna {
3535
pub fn ascii(input: &str) -> &str {
3636
unsafe {
3737
let out = ffi::ada_idna_to_ascii(input.as_ptr().cast(), input.len());
38-
let slice = std::slice::from_raw_parts(out.data.cast(), out.length);
39-
std::str::from_utf8_unchecked(slice)
38+
let slice = core::slice::from_raw_parts(out.data.cast(), out.length);
39+
core::str::from_utf8_unchecked(slice)
4040
}
4141
}
4242
}

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ pub mod ffi;
3535
mod idna;
3636
pub use idna::Idna;
3737

38+
use core::{borrow, ffi::c_uint, fmt, hash, ops};
3839
use derive_more::{Display, Error};
39-
use std::{borrow, fmt, hash, ops, os::raw::c_uint};
4040

41-
extern crate alloc;
4241
#[cfg(feature = "serde")]
4342
extern crate serde;
4443

@@ -229,8 +228,8 @@ impl Url {
229228
pub fn origin(&self) -> &str {
230229
unsafe {
231230
let out = ffi::ada_get_origin(self.0);
232-
let slice = std::slice::from_raw_parts(out.data.cast(), out.length);
233-
std::str::from_utf8_unchecked(slice)
231+
let slice = core::slice::from_raw_parts(out.data.cast(), out.length);
232+
core::str::from_utf8_unchecked(slice)
234233
}
235234
}
236235

0 commit comments

Comments
 (0)