diff --git a/source/durandal/bin.rs b/source/durandal/bin.rs index 3e27504..3bb6f1e 100644 --- a/source/durandal/bin.rs +++ b/source/durandal/bin.rs @@ -145,8 +145,7 @@ macro_rules! rd_impl { /// argument. The function's result has the `?` operator applied to it, /// unless `OPTS` is `no_try`. /// - `OPT`, if not one of the things listed above, may be `enum TYPE` to apply -/// an enumeration made by `c_enum!`, or `flag TYPE` to apply a bitfield made -/// by `bitflags!`. +/// `TryFrom`, or `flag TYPE` to apply a bitfield made by `bitflags!`. /// - `INDEX` is either an integer literal which must be representable as /// `usize`, or a range with the syntax `INDEX; SIZE` denoting the beginning /// and size of the range. diff --git a/source/durandal/cenum.rs b/source/durandal/cenum.rs index dd2a34d..8c0ffb2 100644 --- a/source/durandal/cenum.rs +++ b/source/durandal/cenum.rs @@ -6,7 +6,7 @@ /// The syntax is similar to the `bitflags` macro, but each value has the /// syntax `value => enumeration`. `enum` is used instead of `struct`. /// -/// This will generate an `enum $t` as well as a function `$t::try_from` which +/// This will generate an `enum $t` as well as implement `TryFrom` on it which /// will return `Result<$t, ReprError>`. /// /// # Examples @@ -49,10 +49,13 @@ macro_rules! c_enum $($en = $va,)+ } - impl $t + #[allow(unused_qualifications)] + impl std::convert::TryFrom<$ti> for $t { + type Error = ReprError; + /// Returns, if representable, the variant of `Self` from `n`. - $vi fn try_from(n: $ti) -> Result + fn try_from(n: $ti) -> Result { match n { $($va => Ok($t::$en),)+ diff --git a/source/durandal/ffi.rs b/source/durandal/ffi.rs index ab1f8fc..194d222 100644 --- a/source/durandal/ffi.rs +++ b/source/durandal/ffi.rs @@ -21,19 +21,12 @@ pub const fn null_mut_void() -> *mut c_void {null_mut()} impl CStringVec { - /// Creates a new empty CStringVec. - #[inline] - pub fn new() -> Self - { - Self{sv: Vec::new(), cv: vec![null()]} - } - /// Creates a new `CStringVec` from an iterator. #[inline] - pub fn new_from_iter<'a, I: Iterator>(it: I) - -> ResultS + pub fn new_from_iter<'a, I>(it: I) -> ResultS + where I: Iterator { - let mut v = Self::new(); + let mut v = Self::default(); for st in it { v.push(CString::new(st)?); @@ -61,8 +54,9 @@ impl CStringVec impl Default for CStringVec { + /// Creates a new empty CStringVec. #[inline] - fn default() -> Self {Self::new()} + fn default() -> Self {Self{sv: Vec::new(), cv: vec![null()]}} } /// An owned null-terminated string vector. diff --git a/source/marathon/map/lite.rs b/source/marathon/map/lite.rs index ee00c0c..b8aef8f 100644 --- a/source/marathon/map/lite.rs +++ b/source/marathon/map/lite.rs @@ -3,6 +3,7 @@ use super::{ltfn, TICKS_PER_SECOND}; use crate::durandal::{err::*, fixed::Fixed}; use bitflags::bitflags; +use std::convert::TryFrom; /// Reads a `LITE` chunk. pub fn read(b: &[u8]) -> ResultS<(Light, usize)> diff --git a/source/marathon/map/ltfn.rs b/source/marathon/map/ltfn.rs index 54e0364..88e71db 100644 --- a/source/marathon/map/ltfn.rs +++ b/source/marathon/map/ltfn.rs @@ -1,6 +1,7 @@ //! `LightFunc` type. use crate::durandal::{err::*, fixed::Fixed}; +use std::convert::TryFrom; /// Reads a `LightFunc` object. pub fn read(b: &[u8]) -> ResultS diff --git a/source/marathon/map/medi.rs b/source/marathon/map/medi.rs index 57c38d2..a32aa6f 100644 --- a/source/marathon/map/medi.rs +++ b/source/marathon/map/medi.rs @@ -6,6 +6,7 @@ use crate::{durandal::{bin::OptU16, fixed::{Angle, Fixed, Unit}}, marathon::xfer::TransferMode}; use bitflags::bitflags; +use std::convert::TryFrom; /// Reads a `medi` chunk. pub fn read(b: &[u8]) -> ResultS<(Media, usize)> diff --git a/source/marathon/map/poly.rs b/source/marathon/map/poly.rs index 8f5dad4..f13b083 100644 --- a/source/marathon/map/poly.rs +++ b/source/marathon/map/poly.rs @@ -4,6 +4,7 @@ use super::pnts; use crate::{durandal::{bin::OptU16, err::*, fixed::Unit}, marathon::xfer::TransferMode}; use bitflags::bitflags; +use std::convert::TryFrom; /// Reads a polygon for either M1 or M2. pub fn read_poly_inter(b: &[u8]) -> ResultS diff --git a/source/marathon/map/sids.rs b/source/marathon/map/sids.rs index 77a8a90..cced9a7 100644 --- a/source/marathon/map/sids.rs +++ b/source/marathon/map/sids.rs @@ -4,6 +4,7 @@ use super::stex; use crate::{durandal::{bin::OptU16, err::*, fixed::Fixed}, marathon::xfer::TransferMode}; use bitflags::bitflags; +use std::convert::TryFrom; /// Reads a `SIDS` chunk. pub fn read(b: &[u8]) -> ResultS<(Side, usize)> diff --git a/source/marathon/phy/damg.rs b/source/marathon/phy/damg.rs index 15a0d40..7dd1c9f 100644 --- a/source/marathon/phy/damg.rs +++ b/source/marathon/phy/damg.rs @@ -2,6 +2,7 @@ use crate::durandal::{err::*, fixed::Fixed}; use bitflags::bitflags; +use std::convert::TryFrom; /// Reads a `Damage` object. pub fn read(b: &[u8]) -> ResultS diff --git a/source/marathon/phy/trig.rs b/source/marathon/phy/trig.rs index 39e551d..15a7546 100644 --- a/source/marathon/phy/trig.rs +++ b/source/marathon/phy/trig.rs @@ -1,6 +1,7 @@ //! `Monster` type. use crate::durandal::{bin::OptU16, err::*, fixed::Unit}; +use std::convert::TryFrom; /// Reads a `Trigger` object. pub fn read(b: &[u8]) -> ResultS diff --git a/source/marathon/phy/wppx.rs b/source/marathon/phy/wppx.rs index 679bbd6..5e7a06d 100644 --- a/source/marathon/phy/wppx.rs +++ b/source/marathon/phy/wppx.rs @@ -2,6 +2,7 @@ use crate::durandal::{bin::OptU16, err::*, fixed::Fixed}; use bitflags::bitflags; +use std::convert::TryFrom; use super::trig; diff --git a/source/marathon/pict.rs b/source/marathon/pict.rs index 4c477f3..68a4c31 100644 --- a/source/marathon/pict.rs +++ b/source/marathon/pict.rs @@ -1,6 +1,7 @@ //! QuickDraw PICT format loader. use crate::durandal::{bin::*, err::*, image::*}; +use std::convert::TryFrom; // Reads a `PixMap` header. fn read_pm_header<'a>(b: &'a [u8], diff --git a/source/marathon/shp.rs b/source/marathon/shp.rs index c907879..d7e17bc 100644 --- a/source/marathon/shp.rs +++ b/source/marathon/shp.rs @@ -3,6 +3,7 @@ use crate::{durandal::{bin::*, err::*, fixed::*, image::*}, marathon::{text::*, xfer::TransferMode}}; use bitflags::bitflags; +use std::convert::TryFrom; // Reads a color from a color table into `clut`. fn read_color(b: &[u8], clut: &mut [ColorShp]) -> ResultS<()> diff --git a/source/marathon/snd.rs b/source/marathon/snd.rs index 00d4e49..ea1d344 100644 --- a/source/marathon/snd.rs +++ b/source/marathon/snd.rs @@ -2,7 +2,7 @@ use crate::durandal::{bin::*, err::*, fixed::*, sound::*}; use bitflags::bitflags; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, convert::TryFrom}; /// Reads a sound. pub fn read_sound(b: &[u8]) -> ResultS diff --git a/source/marathon/wad.rs b/source/marathon/wad.rs index 01a54ec..3118bb6 100644 --- a/source/marathon/wad.rs +++ b/source/marathon/wad.rs @@ -2,7 +2,7 @@ use crate::{durandal::{bin::*, err::*, image}, marathon::{map, phy, pict, text::mac_roman_cstr}}; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, convert::TryFrom}; /// Reads all chunks in an entry. pub fn read_chunks(b: &[u8], old: bool, siz_cnk: usize) -> ResultS>