Question: I'm trying to understand the borrow checker. I have a function with the signature 

```
fn SerializeChar(&mut self, value: &mut u8)

```

I would like to get data from `u8` and `i8` because I don't care about the sign:

```
let mut test: i8 = 0; 
thing.SerializeChar(&mut test); //Error: &mut u8 expected

```

That's fine, but how exactly do I cast this? 

`&mut (test as u8)` is not the same thing. Is there any safe or unsafe way to pass test as an argument to `SerializeChar` similar to just casting in C++? Also I would not want to destroy `test` when I do it, as I still need `test`, and still want it as an `i8`, not a `u8`. 

I'm not trying to clone the value. I want the address to `test`, because data in `SerializeChar` is mutable and needs to modify whatever is put in. In C++ terms I don't want a `char`, I want a `*char` because I need to modify 8 bits in memory. It's possible that I can do two separate versions of `SerializeChar`, but before that I wanted to know if it's possible to actually do something like `*u8(test)` that the borrow checker is okay with.

Answer: 
You can't do this safely. Once you have a `&mut` reference to a `u8`, the code using it can only treat it as a `u8`, and you'd need some unsafe code to do the conversions.

`as` works with primitive numeric values because it copies the data in memory, and it can take care of any conversions at that point. This won't work with a reference because it can't change the original value.

If you absolutely can't change the signature of `thing.serialize_char`, *and* you can't change the type of the `test` variable, a workaround is to use another variable and then update the original afterwards:

```
let mut test: i8 = 0; 

let mut test_u8 = test as u8;
thing.serialize_char(&mut test_u8);
test = test_u8 as i8;

```

This will not work if `serialize_char` needs the reference for longer than the function call - but if that is the case the borrow-checker will soon let you know!
Traits in Rust can be generic, so you can define a trait with signature like this:

```rust
trait SerializeChar<T> {
    fn serialize_char(&mut self, value: &mut T);
}

```

and then implement it for your structure with `T = u8` and `T = i8`: 

```rust
struct Thing {}

impl SerializeChar<u8> for Thing {
    fn serialize_char(&mut self, value: &mut u8) { *value = 55; }
}

impl SerializeChar<i8> for Thing {
    fn serialize_char(&mut self, value: &mut i8) { *value = 56; }
}

```

test:

```rust
fn main() {
    let mut a = 0u8;
    let mut b = 0i8;
    let mut thing = Thing{};
    thing.serialize_char(&mut a);
    thing.serialize_char(&mut b);
    dbg!(a);
    dbg!(b);
}

```