Crate vatfluid [] [src]

Zero allocation UTF-8 validation on &[u8] slices. Allows for incomplete UTF-8 sequences. Returns the position in the buffer that has been validated successfully.

use vatfluid::{Error, ErrorKind, Success, validate};

// A `Complete` result.
let buf = b"Hello, World!";
match validate(buf) {
    Ok(Success::Complete(pos)) => {
        assert!(pos == 13);
        assert!(pos == buf.len());
    }
    Ok(Success::Incomplete(_needed, _pos)) => {
        assert!(false);
    }
    Err(_e) => {
        assert!(false);
    }
}

// An `Incomplete` result.
let inc_buf = vec![0xc2, 0xa2, 0xc2];
match validate(&inc_buf) {
    Ok(Success::Complete(_pos)) => {
        assert!(false);
    }
    Ok(Success::Incomplete(needed, pos)) => {
        assert!(needed == 1);
        assert!(pos == 2);
    }
    Err(_e) => {
        assert!(false);
    }
}

// An `Error` result.
let error_buf = vec![0xf4, 0x90, 0x80, 0x80];
match validate(&error_buf) {
    Ok(Success::Complete(_pos)) => {
        assert!(false);
    }
    Ok(Success::Incomplete(_needed, _pos)) => {
        assert!(false);
    }
    Err(e) => {
        assert_matches!(e, Error(ErrorKind::BeyondMaximumCodePoint, _));
    }
}

Structs

Error

The Error type.

Enums

ErrorKind

The kind of an error.

Success

A successful validation result.

Functions

validate

Validate a UTF-8 sequence