8000 move CStr8, CStr16, and CString16 from uefi to ucs2 by phip1611 · Pull Request #23 · rust-osdev/ucs2-rs · GitHub
[go: up one dir, main page]

Skip to content

move CStr8, CStr16, and CString16 from uefi to ucs2 #23

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
init modules cstr8 and cstr16 (plus dependencies)
  • Loading branch information
phip1611 committed Jul 30, 2024
commit 0018d87220e0e1c325c816d8de7239d5dd575817
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ bit_field = "0.10"
[features]
default = []
alloc = []
unstable = []
4 changes: 2 additions & 2 deletions src/encoding/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ macro_rules! ucs2_cstr {
// Use `const` values here to force errors to happen at compile
// time.

const NUM_CHARS: usize = match $crate::str_num_ucs2_chars($s) {
const NUM_CHARS: usize = match $crate::encoding::str_num_ucs2_chars($s) {
// Add one for the null char.
Ok(num) => num + 1,
Err(_) => panic!("input contains a character which cannot be represented in UCS-2"),
};

const VAL: [u16; NUM_CHARS] = match $crate::str_to_ucs2($s) {
const VAL: [u16; NUM_CHARS] = match $crate::encoding::str_to_ucs2($s) {
Ok(val) => val,
// The string was already checked by `str_num_ucs2_chars`,
// so this error is unreachable.
Expand Down
1 change: 1 addition & 0 deletions src/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod macros;

pub use crate::ucs2_cstr;
/// These need to be public for the `ucs2_cstr!` macro, but are not
/// intended to be called directly.
#[doc(hidden)]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
extern crate alloc;

pub mod encoding;
pub mod polyfill;
pub mod types;
29 changes: 29 additions & 0 deletions src/polyfill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Polyfills for functions in the standard library that are currently gated
//! behind unstable features.

use core::mem::MaybeUninit;
#[cfg(feature = "alloc")]
use {alloc::vec::Vec, core::mem::ManuallyDrop};

/// Polyfill for the unstable `MaybeUninit::slice_assume_init_ref` function.
///
/// See <https://github.com/rust-lang/rust/issues/63569>.
pub const unsafe fn maybe_uninit_slice_assume_init_ref<T>(s: &[MaybeUninit<T>]) -> &[T] {
unsafe { &*(s as *const [MaybeUninit<T>] as *const [T]) }
}

/// Polyfill for the unstable `MaybeUninit::slice_as_mut_ptr` function.
///
/// See <https://github.com/rust-lang/rust/issues/63569>.
pub fn maybe_uninit_slice_as_mut_ptr<T>(s: &mut [MaybeUninit<T>]) -> *mut T {
s.as_mut_ptr().cast::<T>()
}

/// Polyfill for the unstable `Vec::into_raw_parts` function.
///
/// See <https://github.com/rust-lang/rust/issues/65816>.
#[cfg(feature = "alloc")]
pub fn vec_into_raw_parts<T>(v: Vec<T>) -> (*mut T, usize, usize) {
let mut v = ManuallyDrop::new(v);
(v.as_mut_ptr(), v.len(), v.capacity())
}
Loading
0