Skip to content

Commit

Permalink
chore: format code snippets in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Sep 28, 2023
1 parent 5a18bba commit 7f6b6cb
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions crates/dyn-abi/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct StructProp {
/// assert_eq!(
/// ty,
/// DynSolType::Array(Box::new(DynSolType::Tuple(vec![
/// DynSolType::Bool,
/// DynSolType::Address,
/// DynSolType::Bool,
/// DynSolType::Address,
/// ])))
/// );
/// assert_eq!(ty.sol_type_name(), type_name);
Expand Down
13 changes: 3 additions & 10 deletions crates/sol-type-parser/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ use winnow::{trace::trace, PResult, Parser};
/// assert_eq!(root_type.span(), "uint256");
///
/// // Allows unknown types
/// assert_eq!(
/// RootType::try_from("MyStruct")?.span(),
/// "MyStruct",
/// );
/// assert_eq!(RootType::try_from("MyStruct")?.span(), "MyStruct",);
///
/// // No sequences
/// assert!(
/// RootType::try_from("uint256[2]").is_err()
/// );
/// assert!(RootType::try_from("uint256[2]").is_err());
///
/// // No tuples
/// assert!(
/// RootType::try_from("(uint256,uint256)").is_err()
/// );
/// assert!(RootType::try_from("(uint256,uint256)").is_err());
/// # Ok::<_, alloy_sol_type_parser::Error>(())
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
5 changes: 4 additions & 1 deletion crates/sol-type-parser/src/stem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use winnow::{trace::trace, PResult, Parser};
/// let stem = TypeStem::try_from("uint256")?;
/// assert_eq!(stem.span(), "uint256");
/// assert!(matches!(stem, TypeStem::Root(_)));
/// assert_eq!(stem.as_root(), Some(&RootType::try_from("uint256").unwrap()));
/// assert_eq!(
/// stem.as_root(),
/// Some(&RootType::try_from("uint256").unwrap())
/// );
///
/// let stem = TypeStem::try_from("(uint256,bool)")?;
/// assert_eq!(stem.span(), "(uint256,bool)");
Expand Down
4 changes: 1 addition & 3 deletions crates/sol-type-parser/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use winnow::{
/// assert_eq!(spec.types[0].span(), "uint256");
///
/// // No array suffixes. Use `TypeSpecifier` instead.
/// assert!(
/// TupleSpecifier::try_from("(uint256,uint256)[]").is_err()
/// );
/// assert!(TupleSpecifier::try_from("(uint256,uint256)[]").is_err());
/// # Ok::<_, alloy_sol_type_parser::Error>(())
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions crates/sol-types/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ impl Eip712Domain {
/// # use alloy_sol_types::{Eip712Domain, eip712_domain};
/// # use alloy_primitives::keccak256;
///
/// const MY_DOMAIN: Eip712Domain = eip712_domain!{
/// const MY_DOMAIN: Eip712Domain = eip712_domain! {
/// name: "MyCoolProtocol",
/// };
///
/// # fn main() {
/// let my_other_domain: Eip712Domain = eip712_domain!{
/// let my_other_domain: Eip712Domain = eip712_domain! {
/// name: String::from("MyCoolProtocol"),
/// version: "1.0.0",
/// salt: keccak256("my domain salt"),
Expand Down
7 changes: 2 additions & 5 deletions crates/sol-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! `encode` and `decode` methods operate on objects implementing [`TokenType`].
//!
//! ```
//! use alloy_sol_types::{SolType, sol_data::*};
//! use alloy_sol_types::{sol_data::*, SolType};
//! # pub fn main() -> alloy_sol_types::Result<()> {
//! // Represent a Solidity type in rust
//! type MySolType = FixedArray<Bool, 2>;
Expand Down Expand Up @@ -113,10 +113,7 @@
//! # pub fn main() {
//! // UDTs are encoded as their underlying type
//! let mvt = MyValueType::from(U256::from(1));
//! assert_eq!(
//! mvt.encode(),
//! sol_data::Uint::<256>::encode(&U256::from(1))
//! );
//! assert_eq!(mvt.encode(), sol_data::Uint::<256>::encode(&U256::from(1)));
//! # }
//! ```
//!
Expand Down
12 changes: 9 additions & 3 deletions crates/sol-types/src/types/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Encodable<T: ?Sized + SolType> {
/// complex Solidity types.
///
/// ```
/// use alloy_sol_types::{SolType, sol_data::*};
/// use alloy_sol_types::{sol_data::*, SolType};
///
/// type DynUint256Array = Array<Uint<256>>;
/// assert_eq!(&DynUint256Array::sol_type_name(), "uint256[]");
Expand All @@ -94,7 +94,10 @@ pub trait Encodable<T: ?Sized + SolType> {
/// assert_eq!(&Erc20FunctionArgs::sol_type_name(), "(address,uint256)");
///
/// type LargeComplexType = (FixedArray<Array<Bool>, 2>, (FixedBytes<13>, String));
/// assert_eq!(&LargeComplexType::sol_type_name(), "(bool[][2],(bytes13,string))");
/// assert_eq!(
/// &LargeComplexType::sol_type_name(),
/// "(bool[][2],(bytes13,string))"
/// );
/// ```
///
/// These types are zero cost representations of Solidity types. They do not
Expand All @@ -117,7 +120,10 @@ pub trait Encodable<T: ?Sized + SolType> {
///
/// // This is the native rust representation of a Solidity type!
/// // How cool is that!
/// const MY_STRUCT: MyStruct = MyStruct { a: true, b: alloy_primitives::FixedBytes([0x01, 0x02]) };
/// const MY_STRUCT: MyStruct = MyStruct {
/// a: true,
/// b: alloy_primitives::FixedBytes([0x01, 0x02]),
/// };
/// ```
pub trait SolType {
/// The corresponding Rust type.
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ comment_width = 80
imports_granularity = "Crate"
trailing_semicolon = false
wrap_comments = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 100

0 comments on commit 7f6b6cb

Please sign in to comment.