title: Rust Setup sidebar_position: 5 id: rust license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Fory Rust provides xlang and native Object Serialization, standard Row Format, generated models, and Fory gRPC. The public fory crate is published on crates.io, supports Rust 1.70 or later, and uses the Rust 2021 edition.
rustc --version cargo --version
Add the public crate:
[dependencies] fory = "1.5.0"
use fory::{Error, Fory, ForyStruct}; #[derive(ForyStruct, Debug, PartialEq)] struct User { id: i64, name: String, } fn main() -> Result<(), Error> { let mut fory = Fory::builder().xlang(true).build(); fory.register::<User>(1)?; let user = User { id: 1, name: "Alice".to_string(), }; let bytes = fory.serialize(&user)?; let decoded: User = fory.deserialize(&bytes)?; assert_eq!(user, decoded); Ok(()) }
Use xlang mode for cross-language data and native mode for Rust-only data. Continue with Rust Object Serialization, configuration, and type registration.