diff --git a/.travis.yml b/.travis.yml index 48649c8..5561513 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ cache: cargo rust: - stable - beta - - 1.34.0 + - 1.40.0 jobs: include: - - rust: 1.34.0 + - rust: 1.40.0 env: TEST_MINIMAL_VERSIONS=1 - - rust: 1.34.0 + - rust: 1.40.0 env: LINT=1 before_install: - | @@ -28,8 +28,7 @@ before_script: cargo +nightly update -Z minimal-versions fi script: - # TODO: Use `--workspace` instead of `--all` for Rust 1.39 or later. - - if [ "${LINT:-0}" -eq 0 ] ; then cargo build --verbose --all --all-features && cargo test --verbose --all --all-features ; fi + - if [ "${LINT:-0}" -eq 0 ] ; then cargo build --verbose --workspace --all-features && cargo test --verbose --workspace --all-features ; fi # Fail if the code is correctly formatted. - if [ "${LINT:-0}" -ne 0 ] ; then cargo fmt --all -- --check ; fi # Fail if the code has warnings. diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e98c8..7fddc3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ ## [Unreleased] +## [0.6.0] + +* Minimum supported Rust version is bumped to 1.40.0. +* Add an FBX version field to `any::AnyTree::V7400` variant + (372a2f6e0314eed86cc2c493d2e2fc86aa226781). +* Add `any::AnyTree::fbx_version()` method (372a2f6e0314eed86cc2c493d2e2fc86aa226781). + +### Breaking changes +* Add an FBX version field to `any::AnyTree::V7400` variant + (372a2f6e0314eed86cc2c493d2e2fc86aa226781). + + This is mainly used by newly added `any::AnyTree::fbx_version()`, but also useful for users to + know FBX version. + - For example, when users want to re-export the tree, they might want to know FBX version of + the source document. + +### Added +* Add `any::AnyTree::fbx_version()` method (372a2f6e0314eed86cc2c493d2e2fc86aa226781). + + Using this, users can get FBX version of the tree even if the `AnyTree` variant is unknown for + users. + + By this method, users can emit meaningful error message if the tree is returned as unknown + variant. + +### Non-breaking changes +* Use `#[non_exhaustive]` instead of hidden dummy variants for enums + (b4c0cf53fcefb2dc13850e09ac1ff15bc57a68e5). + + Users won't affected by this internal change. + ## [0.5.0] * `pull_parser::error::{DataError, OperationError, Warning}` is now nonexhaustive. @@ -242,8 +269,9 @@ Totally rewritten. -[Unreleased]: -[0.4.4]: +[Unreleased]: +[0.6.0]: +[0.5.0]: [0.4.4]: [0.4.3]: [0.4.2]: diff --git a/Cargo.toml b/Cargo.toml index 7ae8a63..b266481 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fbxcel" -version = "0.5.0" +version = "0.6.0" authors = ["YOSHIOKA Takuma "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/README.md b/README.md index be06ba8..214f69f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://travis-ci.com/lo48576/fbxcel.svg?branch=develop)](https://travis-ci.com/lo48576/fbxcel) [![Latest version](https://img.shields.io/crates/v/fbxcel.svg)](https://crates.io/crates/fbxcel) [![Documentation](https://docs.rs/fbxcel/badge.svg)](https://docs.rs/fbxcel) -![Minimum rustc version: 1.34](https://img.shields.io/badge/rustc-1.34+-lightgray.svg) +![Minimum rustc version: 1.40](https://img.shields.io/badge/rustc-1.40+-lightgray.svg) `fbxcel` is an FBX library for Rust programming language. @@ -37,7 +37,7 @@ Currently there is no plan to support FBX ASCII format. ## Rust version -Latest stable compiler (currently 1.34) is supported. +Latest stable compiler (currently 1.40) is supported. ## License diff --git a/examples/load-tree.rs b/examples/load-tree.rs index 9593a2b..adee28f 100644 --- a/examples/load-tree.rs +++ b/examples/load-tree.rs @@ -16,7 +16,8 @@ pub fn main() { let reader = BufReader::new(file); match AnyTree::from_seekable_reader(reader).expect("Failed to load tree") { - AnyTree::V7400(tree, footer) => { + AnyTree::V7400(fbx_version, tree, footer) => { + println!("FBX version = {:#?}", fbx_version); println!("tree = {:#?}", tree); println!("footer = {:#?}", footer); } diff --git a/src/pull_parser/any.rs b/src/pull_parser/any.rs index 3c4d70a..0b9c5f4 100644 --- a/src/pull_parser/any.rs +++ b/src/pull_parser/any.rs @@ -16,11 +16,10 @@ pub use self::error::{Error, Result}; mod error; /// FBX tree type with any supported version. +#[non_exhaustive] pub enum AnyParser { /// FBX 7.4 or later. V7400(pull_parser::v7400::Parser), - #[doc(hidden)] - __Nonexhaustive, } impl AnyParser { @@ -28,7 +27,6 @@ impl AnyParser { pub fn parser_version(&self) -> ParserVersion { match self { AnyParser::V7400(_) => pull_parser::v7400::Parser::::PARSER_VERSION, - AnyParser::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } @@ -36,7 +34,6 @@ impl AnyParser { pub fn fbx_version(&self) -> FbxVersion { match self { AnyParser::V7400(parser) => parser.fbx_version(), - AnyParser::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } } @@ -69,7 +66,6 @@ pub fn from_reader(mut reader: R) -> Result>> }); Ok(AnyParser::V7400(parser)) } - ParserVersion::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never be used"), } } @@ -88,6 +84,5 @@ pub fn from_seekable_reader(mut reader: R) -> Result unreachable!("`__Nonexhaustive` should never be used"), } } diff --git a/src/pull_parser/any/error.rs b/src/pull_parser/any/error.rs index a025025..f7ce9cc 100644 --- a/src/pull_parser/any/error.rs +++ b/src/pull_parser/any/error.rs @@ -9,20 +9,18 @@ pub type Result = std::result::Result; /// Error. #[derive(Debug)] +#[non_exhaustive] pub enum Error { /// Header error. Header(HeaderError), /// Unsupported version. UnsupportedVersion(FbxVersion), - #[doc(hidden)] - __Nonexhaustive, } impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self { Error::Header(e) => Some(e), - Error::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), _ => None, } } @@ -33,7 +31,6 @@ impl fmt::Display for Error { match self { Error::Header(e) => write!(f, "FBX header error: {}", e), Error::UnsupportedVersion(ver) => write!(f, "Unsupported FBX version: {:?}", ver), - Error::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } } diff --git a/src/pull_parser/error/data.rs b/src/pull_parser/error/data.rs index 3b92ec8..a9a6d20 100644 --- a/src/pull_parser/error/data.rs +++ b/src/pull_parser/error/data.rs @@ -6,6 +6,7 @@ use std::{error, fmt, string::FromUtf8Error}; /// Data error. #[derive(Debug)] +#[non_exhaustive] pub enum DataError { /// Data with broken compression. BrokenCompression(Compression, Box), @@ -43,8 +44,6 @@ pub enum DataError { /// /// The former is the expected, the latter is a description of the actual value. UnexpectedAttribute(String, String), - #[doc(hidden)] - __Nonexhaustive, } impl error::Error for DataError { @@ -88,7 +87,6 @@ impl fmt::Display for DataError { "Unexpected attribute value or type: expected {}, got {}", expected, got ), - DataError::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never used"), } } } diff --git a/src/pull_parser/error/operation.rs b/src/pull_parser/error/operation.rs index b0e18ab..7c12291 100644 --- a/src/pull_parser/error/operation.rs +++ b/src/pull_parser/error/operation.rs @@ -6,6 +6,7 @@ use crate::{low::FbxVersion, pull_parser::ParserVersion}; /// Invalid operation. #[derive(Debug)] +#[non_exhaustive] pub enum OperationError { /// Attempt to parse more data while the parsing is aborted. AlreadyAborted, @@ -13,8 +14,6 @@ pub enum OperationError { AlreadyFinished, /// Attempt to create a parser with unsupported FBX version. UnsupportedFbxVersion(ParserVersion, FbxVersion), - #[doc(hidden)] - __Nonexhaustive, } impl error::Error for OperationError {} @@ -34,7 +33,6 @@ impl fmt::Display for OperationError { "Unsupported FBX version: parser={:?}, fbx={:?}", parser, fbx ), - OperationError::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never used"), } } } diff --git a/src/pull_parser/error/warning.rs b/src/pull_parser/error/warning.rs index 93a750f..2f20e61 100644 --- a/src/pull_parser/error/warning.rs +++ b/src/pull_parser/error/warning.rs @@ -4,6 +4,7 @@ use std::{error, fmt}; /// Warning. #[derive(Debug)] +#[non_exhaustive] pub enum Warning { /// Node name is empty. EmptyNodeName, @@ -23,8 +24,6 @@ pub enum Warning { MissingNodeEndMarker, /// Unexpected value for footer fields (mainly for unknown fields). UnexpectedFooterFieldValue, - #[doc(hidden)] - __Nonexhaustive, } impl error::Error for Warning {} @@ -44,7 +43,6 @@ impl fmt::Display for Warning { ), Warning::MissingNodeEndMarker => write!(f, "Missing node end marker"), Warning::UnexpectedFooterFieldValue => write!(f, "Unexpected footer field value"), - Warning::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never used"), } } } diff --git a/src/pull_parser/version.rs b/src/pull_parser/version.rs index fbec983..4c13d97 100644 --- a/src/pull_parser/version.rs +++ b/src/pull_parser/version.rs @@ -9,11 +9,10 @@ use crate::low::FbxVersion; /// Some parser supports multiple versions of FBX binary. /// Each variants of this type corresponds to a parser implementation. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[non_exhaustive] pub enum ParserVersion { /// FBX 7.4 and 7.5. V7400, - #[doc(hidden)] - __Nonexhaustive, } impl ParserVersion { diff --git a/src/tree.rs b/src/tree.rs index b698f07..b06682d 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -25,7 +25,7 @@ //! // To use readers without `std::io::Seek` implementation, use `from_reader` //! // instead. //! match AnyTree::from_seekable_reader(reader).expect("Failed to load tree") { -//! AnyTree::V7400(tree, footer) => { +//! AnyTree::V7400(fbx_version, tree, footer) => { //! // You got a tree (and footer)! Do what you want! //! } //! // `AnyTree` is nonexhaustive. diff --git a/src/tree/any.rs b/src/tree/any.rs index 68a885b..818f41e 100644 --- a/src/tree/any.rs +++ b/src/tree/any.rs @@ -6,7 +6,7 @@ use log::warn; pub use self::error::{Error, Result}; use crate::{ - low, + low::{self, FbxVersion}, pull_parser::{self, any::AnyParser}, tree, }; @@ -14,14 +14,14 @@ use crate::{ mod error; /// FBX tree type with any supported version. +#[non_exhaustive] pub enum AnyTree { /// FBX 7.4 or later. V7400( + FbxVersion, tree::v7400::Tree, std::result::Result, pull_parser::Error>, ), - #[doc(hidden)] - __Nonexhaustive, } impl AnyTree { @@ -33,15 +33,15 @@ impl AnyTree { pub fn from_reader(reader: impl Read) -> Result { match pull_parser::any::from_reader(reader)? { AnyParser::V7400(mut parser) => { + let fbx_version = parser.fbx_version(); parser.set_warning_handler(|w, pos| { warn!("WARNING: {} (pos={:?})", w, pos); Ok(()) }); let tree_loader = tree::v7400::Loader::new(); let (tree, footer) = tree_loader.load(&mut parser)?; - Ok(AnyTree::V7400(tree, footer)) + Ok(AnyTree::V7400(fbx_version, tree, footer)) } - AnyParser::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never be used"), } } @@ -49,15 +49,22 @@ impl AnyTree { pub fn from_seekable_reader(reader: impl Read + Seek) -> Result { match pull_parser::any::from_seekable_reader(reader)? { AnyParser::V7400(mut parser) => { + let fbx_version = parser.fbx_version(); parser.set_warning_handler(|w, pos| { warn!("WARNING: {} (pos={:?})", w, pos); Ok(()) }); let tree_loader = tree::v7400::Loader::new(); let (tree, footer) = tree_loader.load(&mut parser)?; - Ok(AnyTree::V7400(tree, footer)) + Ok(AnyTree::V7400(fbx_version, tree, footer)) } - AnyParser::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never be used"), + } + } + + /// Returns the FBX version of the document the tree came from. + pub fn fbx_version(&self) -> FbxVersion { + match self { + Self::V7400(ver, _, _) => *ver, } } } diff --git a/src/tree/any/error.rs b/src/tree/any/error.rs index 8b2c602..19530be 100644 --- a/src/tree/any/error.rs +++ b/src/tree/any/error.rs @@ -9,6 +9,7 @@ pub type Result = std::result::Result; /// Error. #[derive(Debug)] +#[non_exhaustive] pub enum Error { /// Parser creation error. ParserCreation(pull_parser::any::Error), @@ -16,8 +17,6 @@ pub enum Error { Parser(pull_parser::Error), /// Tree load error. Tree(Box), - #[doc(hidden)] - __Nonexhaustive, } impl error::Error for Error { @@ -26,7 +25,6 @@ impl error::Error for Error { Error::ParserCreation(e) => Some(e), Error::Parser(e) => Some(e), Error::Tree(e) => Some(&**e), - Error::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } } @@ -37,7 +35,6 @@ impl fmt::Display for Error { Error::ParserCreation(e) => write!(f, "Failed to create a parser: {}", e), Error::Parser(e) => write!(f, "Parser error: {}", e), Error::Tree(e) => write!(f, "Tree load error: {}", e), - Error::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } } diff --git a/src/tree/v7400/error.rs b/src/tree/v7400/error.rs index 07cacb1..52ebc2b 100644 --- a/src/tree/v7400/error.rs +++ b/src/tree/v7400/error.rs @@ -6,6 +6,7 @@ use crate::pull_parser::Error as ParserError; /// FBX data tree load error. #[derive(Debug)] +#[non_exhaustive] pub enum LoadError { /// Bad parser. /// @@ -13,8 +14,6 @@ pub enum LoadError { BadParser, /// Parser error. Parser(ParserError), - #[doc(hidden)] - __Nonexhaustive, } impl fmt::Display for LoadError { @@ -22,7 +21,6 @@ impl fmt::Display for LoadError { match self { LoadError::BadParser => f.write_str("Attempt to use a bad parser"), LoadError::Parser(e) => write!(f, "Parser error: {}", e), - LoadError::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"), } } }