@@ -64,13 +64,14 @@ impl AsciiString {
64
64
/// This is highly unsafe, due to the number of invariants that aren't checked:
65
65
///
66
66
/// * The memory at `buf` need to have been previously allocated by the same allocator this
67
- /// library uses.
67
+ /// library uses, with an alignment of 1 .
68
68
/// * `length` needs to be less than or equal to `capacity`.
69
69
/// * `capacity` needs to be the correct value.
70
70
/// * `buf` must have `length` valid ascii elements and contain a total of `capacity` total,
71
71
/// possibly, uninitialized, elements.
72
+ /// * Nothing else must be using the memory `buf` points to.
72
73
///
73
- /// Violating these may cause problems like corrupting the allocator's internal datastructures .
74
+ /// Violating these may cause problems like corrupting the allocator's internal data structures .
74
75
///
75
76
/// # Examples
76
77
///
@@ -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
/// }
@@ -97,9 +98,9 @@ impl AsciiString {
97
98
#[ must_use]
98
99
pub unsafe fn from_raw_parts ( buf : * mut AsciiChar , length : usize , capacity : usize ) -> Self {
99
100
AsciiString {
100
- // 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.
101
+ // SAFETY: Caller guarantees that `buf` was previously allocated by this library,
102
+ // that `buf` contains `length` valid ascii elements and has a total capacity
103
+ // of `capacity` elements, and that nothing else is using the momory .
103
104
vec : unsafe { Vec :: from_raw_parts ( buf, length, capacity) } ,
104
105
}
105
106
}
0 commit comments