//! When this file is built in release mode, it was discovered that it there is an overflow in requirements: //! //! ```sh //! cargo build --release -p tests --test recursive_models --features test //! ``` //! //! ```text //! error[E0275]: overflow evaluating the requirement `<>::EncodeVariant as VariantEncoder>::EncodeData<'_>: Encoder` //! | //! = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_models`) //! ``` use musli::de::DecodeOwned; use musli::mode::Binary; use musli::{Decode, Encode}; pub(crate) fn encode(changes: &T) -> musli::storage::Result> where T: Encode, { musli::storage::to_vec(changes) } pub(crate) fn decode(buf: &[u8]) -> musli::storage::Result where T: DecodeOwned, { musli::storage::from_slice(buf) } #[test] fn big_model() { #![allow(dead_code)] use std::ffi::OsString; use std::ops::Range; use std::path::PathBuf; use std::sync::Arc; #[derive(Encode, Decode)] #[non_exhaustive] pub(crate) struct RustVersion { pub(crate) major: u64, pub(crate) minor: u64, pub(crate) patch: u64, } #[derive(Encode, Decode)] pub(crate) enum CargoKey {} #[derive(Encode, Decode)] pub(crate) enum CargoIssue {} #[derive(Encode, Decode)] pub(crate) enum WorkflowError { Error { name: String, reason: String }, } #[derive(Encode, Decode)] pub(crate) enum EditChange { Insert { reason: String, key: String, value: Value, }, Set { reason: String, value: Value, }, RemoveKey { reason: String, key: String, }, } #[derive(Encode, Decode)] pub(crate) enum Value { String(String), Array(Vec), Mapping(Vec<(String, Value)>), } #[derive(Encode, Decode)] pub(crate) struct Edits { changes: Vec, } #[derive(Encode, Decode)] pub(crate) struct File { data: String, line_starts: Vec, } #[derive(Encode, Decode)] pub(crate) struct RepoRef {} #[derive(Encode, Decode)] pub(crate) struct Manifest {} #[derive(Encode, Decode)] pub(crate) struct Replaced { path: PathBuf, content: Vec, replacement: Box, ranges: Vec>, } #[derive(Encode, Decode)] pub(crate) enum Change { MissingWorkflow { id: String, repo: RepoRef, }, BadWorkflow { edits: Edits, errors: Vec, }, UpdateLib { lib: Arc, }, UpdateReadme { readme: Arc, }, CargoTomlIssues { cargo: Option, issues: Vec, }, SetRustVersion { repo: RepoRef, version: RustVersion, }, RemoveRustVersion { repo: RepoRef, version: RustVersion, }, SavePackage { manifest: Manifest, }, Replace { replaced: Replaced, }, ReleaseCommit {}, Publish { name: String, dry_run: bool, no_verify: bool, args: Vec, }, } let changes = Vec::::new(); encode(&changes).unwrap(); assert!(decode::>(&[]).is_err()); } #[test] fn recursive_model() { #[derive(Encode, Decode)] pub(crate) struct Value { recursive: Vec, } #[derive(Encode, Decode)] pub(crate) struct Model { value: Value, } let model = Model { value: Value { recursive: Vec::new(), }, }; encode(&model).unwrap(); assert!(decode::(&[]).is_err()); }