Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lo48576 committed Dec 21, 2019
2 parents 782ed2e + f47488c commit 0361b33
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 47 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- |
Expand All @@ -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.
Expand Down
32 changes: 30 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -242,8 +269,9 @@

Totally rewritten.

[Unreleased]: <https://github.com/lo48576/fbxcel/compare/v0.5.0...develop>
[0.4.4]: <https://github.com/lo48576/fbxcel/releases/tag/v0.5.0>
[Unreleased]: <https://github.com/lo48576/fbxcel/compare/v0.6.0...develop>
[0.6.0]: <https://github.com/lo48576/fbxcel/releases/tag/v0.6.0>
[0.5.0]: <https://github.com/lo48576/fbxcel/releases/tag/v0.5.0>
[0.4.4]: <https://github.com/lo48576/fbxcel/releases/tag/v0.4.4>
[0.4.3]: <https://github.com/lo48576/fbxcel/releases/tag/v0.4.3>
[0.4.2]: <https://github.com/lo48576/fbxcel/releases/tag/v0.4.2>
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fbxcel"
version = "0.5.0"
version = "0.6.0"
authors = ["YOSHIOKA Takuma <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion examples/load-tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 1 addition & 6 deletions src/pull_parser/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@ pub use self::error::{Error, Result};
mod error;

/// FBX tree type with any supported version.
#[non_exhaustive]
pub enum AnyParser<R> {
/// FBX 7.4 or later.
V7400(pull_parser::v7400::Parser<R>),
#[doc(hidden)]
__Nonexhaustive,
}

impl<R: ParserSource> AnyParser<R> {
/// Returns the parser version.
pub fn parser_version(&self) -> ParserVersion {
match self {
AnyParser::V7400(_) => pull_parser::v7400::Parser::<R>::PARSER_VERSION,
AnyParser::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"),
}
}

/// Returns the FBX version.
pub fn fbx_version(&self) -> FbxVersion {
match self {
AnyParser::V7400(parser) => parser.fbx_version(),
AnyParser::__Nonexhaustive => panic!("`__Nonexhaustive` should not be used"),
}
}
}
Expand Down Expand Up @@ -69,7 +66,6 @@ pub fn from_reader<R: Read>(mut reader: R) -> Result<AnyParser<PlainSource<R>>>
});
Ok(AnyParser::V7400(parser))
}
ParserVersion::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never be used"),
}
}

Expand All @@ -88,6 +84,5 @@ pub fn from_seekable_reader<R: Read + Seek>(mut reader: R) -> Result<AnyParser<S
});
Ok(AnyParser::V7400(parser))
}
ParserVersion::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never be used"),
}
}
5 changes: 1 addition & 4 deletions src/pull_parser/any/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ pub type Result<T> = std::result::Result<T, Error>;

/// 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,
}
}
Expand All @@ -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"),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/pull_parser/error/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error + Send + Sync>),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/pull_parser/error/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ 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,
/// Attempt to parse more data while the parsing is (successfully) finished.
AlreadyFinished,
/// Attempt to create a parser with unsupported FBX version.
UnsupportedFbxVersion(ParserVersion, FbxVersion),
#[doc(hidden)]
__Nonexhaustive,
}

impl error::Error for OperationError {}
Expand All @@ -34,7 +33,6 @@ impl fmt::Display for OperationError {
"Unsupported FBX version: parser={:?}, fbx={:?}",
parser, fbx
),
OperationError::__Nonexhaustive => unreachable!("`__Nonexhaustive` should never used"),
}
}
}
4 changes: 1 addition & 3 deletions src/pull_parser/error/warning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{error, fmt};

/// Warning.
#[derive(Debug)]
#[non_exhaustive]
pub enum Warning {
/// Node name is empty.
EmptyNodeName,
Expand All @@ -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 {}
Expand All @@ -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"),
}
}
}
3 changes: 1 addition & 2 deletions src/pull_parser/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 14 additions & 7 deletions src/tree/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ use log::warn;

pub use self::error::{Error, Result};
use crate::{
low,
low::{self, FbxVersion},
pull_parser::{self, any::AnyParser},
tree,
};

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<Box<low::v7400::FbxFooter>, pull_parser::Error>,
),
#[doc(hidden)]
__Nonexhaustive,
}

impl AnyTree {
Expand All @@ -33,31 +33,38 @@ impl AnyTree {
pub fn from_reader(reader: impl Read) -> Result<Self> {
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"),
}
}

/// Loads a tree from the given seekable reader.
pub fn from_seekable_reader(reader: impl Read + Seek) -> Result<Self> {
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,
}
}
}
5 changes: 1 addition & 4 deletions src/tree/any/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ pub type Result<T> = std::result::Result<T, Error>;

/// Error.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// Parser creation error.
ParserCreation(pull_parser::any::Error),
/// Parser error.
Parser(pull_parser::Error),
/// Tree load error.
Tree(Box<dyn error::Error + Send + Sync + 'static>),
#[doc(hidden)]
__Nonexhaustive,
}

impl error::Error for Error {
Expand All @@ -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"),
}
}
}
Expand All @@ -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"),
}
}
}
Expand Down
Loading

0 comments on commit 0361b33

Please sign in to comment.