@@ -65,6 +65,7 @@ impl AsciiString {
65
65
///
66
66
/// * The memory at `buf` need to have been previously allocated by the same allocator this
67
67
/// library uses.
68
+ /// * `buf` must be obtained from a valid `&mut` reference to guarentee exclusive ownership.
68
69
/// * `length` needs to be less than or equal to `capacity`.
69
70
/// * `capacity` needs to be the correct value.
70
71
/// * `buf` must have `length` valid ascii elements and contain a total of `capacity` total,
@@ -81,14 +82,14 @@ impl AsciiString {
81
82
/// use std::mem;
82
83
///
83
84
/// unsafe {
84
- /// let s = AsciiString::from_ascii("hello").unwrap();
85
- /// let ptr = s.as_ptr ();
85
+ /// let mut s = AsciiString::from_ascii("hello").unwrap();
86
+ /// let ptr = s.as_mut_ptr ();
86
87
/// let len = s.len();
87
88
/// let capacity = s.capacity();
88
89
///
89
90
/// mem::forget(s);
90
91
///
91
- /// let s = AsciiString::from_raw_parts(ptr as *mut _ , len, capacity);
92
+ /// let s = AsciiString::from_raw_parts(ptr, len, capacity);
92
93
///
93
94
/// assert_eq!(AsciiString::from_ascii("hello").unwrap(), s);
94
95
/// }
@@ -98,8 +99,8 @@ impl AsciiString {
98
99
pub unsafe fn from_raw_parts ( buf : * mut AsciiChar , length : usize , capacity : usize ) -> Self {
99
100
AsciiString {
100
101
// SAFETY: Caller guarantees `buf` was previously allocated by this library,
101
- // that `buf` contains `length` valid ascii elements and has a total
102
- // capacity of `capacity` elements.
102
+ // is a unique pointer, `buf` contains `length` valid ascii elements,
103
+ // and has a total capacity of `capacity` elements.
103
104
vec : unsafe { Vec :: from_raw_parts ( buf, length, capacity) } ,
104
105
}
105
106
}
0 commit comments