Skip to content

Commit

Permalink
Minor cleanups: doc fixes, and clippy suggestions
Browse files Browse the repository at this point in the history
Test that this is compatible back to Rust 1.26.0.

Rust 1.24.0 and earlier fail in the doctest due to
rust-lang/rust#33731
  • Loading branch information
bpfoley authored and tormol committed Feb 9, 2020
1 parent 5518d72 commit 9cdf340
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ while the others will fall back to iterating and collecting.

## Example

```
```rust
extern crate map_in_place;
use map_in_place::MapVecInPlace;
fn main() {
Expand All @@ -26,11 +26,11 @@ fn main() {
}
```

## Why all those restrictions?
The rust allocation interface is a bit more complex than the standard C one of
## Why all those restrictions?
The Rust allocation interface is a bit more complex than the standard C one of
`malloc(size_t)` and `free(void*)`:

First, malloc and free takes the alignment of the types you want to store,
First, `alloc()` and `dealloc()` takes the alignment of the types you want to store,
and allocating with one alignment and freeing with another is undefined behaviour.

Second, Rust requires the owner to know the size of the memory to free,
Expand Down
25 changes: 12 additions & 13 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ I might also change the panic messages.
```
extern crate map_in_place;
use map_in_place::MapVecInPlace;
fn main() {
let v = vec![8_u32,29,14,5];
let v = v.filter_map(|n| if n < 10 {Some( (n as u8+b'0') as char)}
else {None}
);// happens in place
assert_eq!(&v, &['8','5']);
let v = v.map(|c| c as u8);// falls back to iterators
assert_eq!(&v[..], &b"85"[..]);
}
let v = vec![8_u32,29,14,5];
let v = v.filter_map(|n| if n < 10 {Some( (n as u8+b'0') as char)}
else {None}
);// happens in place
assert_eq!(&v, &['8','5']);
let v = v.map(|c| c as u8);// falls back to iterators
assert_eq!(&v[..], &b"85"[..]);
```
*/

Expand All @@ -33,10 +32,10 @@ use std::{mem, ptr};


// Error messages used by {map,retain}_in_place().
static ERR_ZERO_SIZED: &'static str = "Cannot reuse memory for zero-sized types";
static ERR_ALIGNMENT: &'static str = "`A` and `B` have different alignment";
static ERR_NEED_EXACT_SIZE: &'static str = "`A` and `B` have different sizes";
static ERR_NEED_DIVISIBLE_SIZE: &'static str
static ERR_ZERO_SIZED: &str = "Cannot reuse memory for zero-sized types";
static ERR_ALIGNMENT: &str = "`A` and `B` have different alignment";
static ERR_NEED_EXACT_SIZE: &str = "`A` and `B` have different sizes";
static ERR_NEED_DIVISIBLE_SIZE: &str
= "The size of `A` is not equal to or a multiple of the size of `B`";


Expand Down

0 comments on commit 9cdf340

Please sign in to comment.