updates for rust 1.34
parent
4447897302
commit
959930cede
|
@ -7,7 +7,6 @@ homepage = "https://greyserv.net/maraiah/"
|
||||||
repository = "http://git.greyserv.net/marrub/Maraiah"
|
repository = "http://git.greyserv.net/marrub/Maraiah"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "CC0-1.0"
|
license = "CC0-1.0"
|
||||||
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Binary data conversion utilities.
|
//! Binary data conversion utilities.
|
||||||
|
|
||||||
use crate::durandal::err::*;
|
use crate::durandal::err::*;
|
||||||
use std::{fmt, num::NonZeroU16};
|
use std::{convert::{TryFrom, TryInto}, fmt, num::NonZeroU16};
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -161,8 +161,6 @@ macro_rules! rd_impl {
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[macro_use] extern crate maraiah;
|
/// # #[macro_use] extern crate maraiah;
|
||||||
/// # use maraiah::durandal::err::*;
|
/// # use maraiah::durandal::err::*;
|
||||||
/// # fn main() -> ResultS<()>
|
|
||||||
/// # {
|
|
||||||
/// let buffer = &[4, 0, 2, 0, 0, 0, 6];
|
/// let buffer = &[4, 0, 2, 0, 0, 0, 6];
|
||||||
///
|
///
|
||||||
/// read_data! {
|
/// read_data! {
|
||||||
|
@ -179,7 +177,6 @@ macro_rules! rd_impl {
|
||||||
/// assert_eq!(six, 6_u8);
|
/// assert_eq!(six, 6_u8);
|
||||||
/// assert_eq!(byte, &[2, 0, 0, 0]);
|
/// assert_eq!(byte, &[2, 0, 0, 0]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! read_data {
|
macro_rules! read_data {
|
||||||
|
@ -205,7 +202,12 @@ macro_rules! check_data {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Casts a `u32` to a `usize`. For future compatibility.
|
/// Casts a `u32` to a `usize`.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Will panic if the platform does not have a 32-bit `usize`. In this case,
|
||||||
|
/// the application is not supported, but will still run and panic at runtime.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -215,7 +217,7 @@ macro_rules! check_data {
|
||||||
/// assert_eq!(usize_from_u32(777u32), 777usize);
|
/// assert_eq!(usize_from_u32(777u32), 777usize);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn usize_from_u32(n: u32) -> usize {n as usize}
|
pub fn usize_from_u32(n: u32) -> usize {usize::try_from(n).unwrap()}
|
||||||
|
|
||||||
/// Creates an `Ident` from a slice.
|
/// Creates an `Ident` from a slice.
|
||||||
///
|
///
|
||||||
|
@ -231,7 +233,7 @@ pub const fn usize_from_u32(n: u32) -> usize {n as usize}
|
||||||
/// assert_eq!(ident(b"POLY"), Ident([b'P', b'O', b'L', b'Y']));
|
/// assert_eq!(ident(b"POLY"), Ident([b'P', b'O', b'L', b'Y']));
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn ident(b: &[u8]) -> Ident {Ident([b[0], b[1], b[2], b[3]])}
|
pub fn ident(b: &[u8]) -> Ident {Ident(b[0..4].try_into().unwrap())}
|
||||||
|
|
||||||
/// Applies `u32::from_be_bytes` to a slice.
|
/// Applies `u32::from_be_bytes` to a slice.
|
||||||
///
|
///
|
||||||
|
@ -247,7 +249,7 @@ pub const fn ident(b: &[u8]) -> Ident {Ident([b[0], b[1], b[2], b[3]])}
|
||||||
/// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32);
|
/// assert_eq!(u32b(&[0x00, 0x0B, 0xDE, 0x31]), 777_777u32);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn u32b(b: &[u8]) -> u32 {u32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
pub fn u32b(b: &[u8]) -> u32 {u32::from_be_bytes(b[0..4].try_into().unwrap())}
|
||||||
|
|
||||||
/// Applies `u16::from_be_bytes` to a slice.
|
/// Applies `u16::from_be_bytes` to a slice.
|
||||||
///
|
///
|
||||||
|
@ -263,7 +265,7 @@ pub fn u32b(b: &[u8]) -> u32 {u32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
||||||
/// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16);
|
/// assert_eq!(u16b(&[0x1E, 0x61]), 7_777u16);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn u16b(b: &[u8]) -> u16 {u16::from_be_bytes([b[0], b[1]])}
|
pub fn u16b(b: &[u8]) -> u16 {u16::from_be_bytes(b[0..2].try_into().unwrap())}
|
||||||
|
|
||||||
/// Applies `i32::from_be_bytes` to a slice.
|
/// Applies `i32::from_be_bytes` to a slice.
|
||||||
///
|
///
|
||||||
|
@ -279,7 +281,7 @@ pub fn u16b(b: &[u8]) -> u16 {u16::from_be_bytes([b[0], b[1]])}
|
||||||
/// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32);
|
/// assert_eq!(i32b(&[0xFF, 0x89, 0x52, 0x0F]), -7_777_777i32);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn i32b(b: &[u8]) -> i32 {i32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
pub fn i32b(b: &[u8]) -> i32 {i32::from_be_bytes(b[0..4].try_into().unwrap())}
|
||||||
|
|
||||||
/// Applies `i16::from_be_bytes` to a slice.
|
/// Applies `i16::from_be_bytes` to a slice.
|
||||||
///
|
///
|
||||||
|
@ -295,7 +297,7 @@ pub fn i32b(b: &[u8]) -> i32 {i32::from_be_bytes([b[0], b[1], b[2], b[3]])}
|
||||||
/// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16);
|
/// assert_eq!(i16b(&[0xE1, 0x9F]), -7_777i16);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn i16b(b: &[u8]) -> i16 {i16::from_be_bytes([b[0], b[1]])}
|
pub fn i16b(b: &[u8]) -> i16 {i16::from_be_bytes(b[0..2].try_into().unwrap())}
|
||||||
|
|
||||||
/// Applies a read function over a slice.
|
/// Applies a read function over a slice.
|
||||||
///
|
///
|
||||||
|
|
|
@ -3,7 +3,6 @@ name = "maraiah-tycho"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Alison Sanderson <marrub@greyserv.net>"]
|
authors = ["Alison Sanderson <marrub@greyserv.net>"]
|
||||||
description = "Tycho map editor."
|
description = "Tycho map editor."
|
||||||
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue