Skip to content

Commit

Permalink
basic example: add **impl** block
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Feb 13, 2025
1 parent 1f3c071 commit bbe70f9
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions near-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! near-sdk = "5.6.0"
//! ```
//!
//! ### Example: Counter Smart Contract. For more information, see the [near] documentation.
//! ### Example: Counter Smart Contract. For more information, see the [**near** macro](near) documentation.
//!
//! Below is an example of a simple counter contract that increments and retrieves a value:
//!
Expand Down Expand Up @@ -102,8 +102,8 @@ extern crate quickcheck;
/// to generate the necessary code to expose `pub` methods from the contract as well
/// as generating the glue code to be a valid NEAR contract.
///
/// The macro is a syntactic sugar for [near_bindgen] and expands to the [near_bindgen] macro invocations.
/// Both of them share the same attributes, except for those that are explicitly marked as specific to the [near] macro. ([1](near#nearserializers-annotates-structsenums), [2](near#nearcontract_state-annotates-structsenums))
/// The macro is a syntactic sugar for [**near_bindgen**](near_bindgen) and expands to the [**near_bindgen**](near_bindgen) macro invocations.
/// Both of them share the same attributes, except for those that are explicitly marked as specific to the [**near**](near) macro. ([1](near#nearserializers-annotates-structsenums), [2](near#nearcontract_state-annotates-structsenums))
///
/// # Attributes
///
Expand All @@ -119,9 +119,36 @@ extern crate quickcheck;
///
/// #[near(contract_state)]
/// pub struct Contract {
/// data: i8,
/// greeting: String,
/// }
/// ```
/// which usually comes paired with at least one **impl** block for the contract type,
/// annotated with a plain `#[near]` attribute:
///
/// ```rust
/// # use near_sdk::{near, log};
///
/// # #[near(contract_state)]
/// # pub struct Contract {
/// # greeting: String,
/// # }
/// #[near]
/// impl Contract {
/// // view method
/// pub fn get_greeting(&self) -> String {
/// self.greeting.clone()
/// }
///
/// // mutating method
/// pub fn set_greeting(&mut self, greeting: String) {
/// log!("Saving greeting: {greeting}");
/// self.greeting = greeting;
/// }
/// }
/// ```
///
/// It makes little sense to define
/// contract state without contract-specific methods to view and mutate its state.
///
/// ## `#[near(serializers=[...])` (annotates structs/enums)
///
Expand Down

0 comments on commit bbe70f9

Please sign in to comment.