@@ -64,13 +64,14 @@ impl AsciiString {
6464 /// This is highly unsafe, due to the number of invariants that aren't checked:
6565 ///
6666 /// * 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 .
6868 /// * `length` needs to be less than or equal to `capacity`.
6969 /// * `capacity` needs to be the correct value.
7070 /// * `buf` must have `length` valid ascii elements and contain a total of `capacity` total,
7171 /// possibly, uninitialized, elements.
72+ /// * Nothing else must be using the memory `buf` points to.
7273 ///
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 .
7475 ///
7576 /// # Examples
7677 ///
@@ -81,14 +82,14 @@ impl AsciiString {
8182 /// use std::mem;
8283 ///
8384 /// 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 ();
8687 /// let len = s.len();
8788 /// let capacity = s.capacity();
8889 ///
8990 /// mem::forget(s);
9091 ///
91- /// let s = AsciiString::from_raw_parts(ptr as *mut _ , len, capacity);
92+ /// let s = AsciiString::from_raw_parts(ptr, len, capacity);
9293 ///
9394 /// assert_eq!(AsciiString::from_ascii("hello").unwrap(), s);
9495 /// }
@@ -97,9 +98,9 @@ impl AsciiString {
9798 #[ must_use]
9899 pub unsafe fn from_raw_parts ( buf : * mut AsciiChar , length : usize , capacity : usize ) -> Self {
99100 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 .
103104 vec : unsafe { Vec :: from_raw_parts ( buf, length, capacity) } ,
104105 }
105106 }
0 commit comments