mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Made unsafely safe functions unsafe again, for safety
This commit is contained in:
parent
276293af7c
commit
4357cbf2fa
@ -2319,20 +2319,20 @@ pub mod raw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
||||||
pub fn pop_byte(s: &mut ~str) -> u8 {
|
pub unsafe fn pop_byte(s: &mut ~str) -> u8 {
|
||||||
let len = len(*s);
|
let len = len(*s);
|
||||||
assert!((len > 0u));
|
assert!((len > 0u));
|
||||||
let b = s[len - 1u];
|
let b = s[len - 1u];
|
||||||
unsafe { set_len(s, len - 1u) };
|
set_len(s, len - 1u);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
|
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
|
||||||
pub fn shift_byte(s: &mut ~str) -> u8 {
|
pub unsafe fn shift_byte(s: &mut ~str) -> u8 {
|
||||||
let len = len(*s);
|
let len = len(*s);
|
||||||
assert!((len > 0u));
|
assert!((len > 0u));
|
||||||
let b = s[0];
|
let b = s[0];
|
||||||
*s = unsafe { raw::slice_bytes_owned(*s, 1u, len) };
|
*s = raw::slice_bytes_owned(*s, 1u, len);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user