Need review for my library


#1

Hello all. I’ve write library that implement external data representation. That is my first rust code, so I need advice from more expirienced people.


#2

README’s are nice :smile:

mixing tabs and spaces :frowning:

Why are you calling error::Error::description(err) manually (instead of calling err.description())?

Rust users generally don’t put a space before : and do put one after. Also, we generally don’t put a ; at the end of statements ending in } (except in a let binding (let a = { /* ... */ };)).

XdrWriter::get_buffer should probably be named XdrWriter::into_buffer.

You have quite a few functions that return Results but always return Ok. However, inside these functions, you repeatedly call unwrap() (which panics on errors). You might want to consider using the try! macro to return the error instead.

The read_form_xdr implementations and unpack_array could be simplified with a little functional programming. For example, unpack_array can be reduced to:

(0..n).map(|_| T::read_from_xdr(self)).collect()

PADDING should probably be a const.

You probably don’t need so many type annotations.

Also, FYI, to_string is slow because it uses the formatting library. You should generally prefer to_owned (i.e. "my string".to_owned()) or String::from (String::from("my string")). This is a rather unfortunate pitfall for new users.


#3

In progress :smile:

Grrr… different environments, different editors. My bad.

Okay.

I use so many unwrap just to make first prototype. Error handling in progress.

Maybe, but try to explain it to compiler :smile:

Thanks.


#4

I’ve sent you a small pull request for your README.md.…

I also prefer using tabs to intent something which is intended to be executed on a shell because it is easier to copy and paste it.