-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: document callback_unwrap
attribute
#1313
docs: document callback_unwrap
attribute
#1313
Conversation
Fixes near#1303 Adds documentation for the `callback_unwrap` attribute under the `#[near]` macro docs, including: - Description of functionality and usage - Integration with `PromiseOrValue` - Cross-contract factorial example - Error handling alternatives - Rust doc annotations and references Resolves near#1303 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/near/near-sdk-rs/issues/1303?shareId=XXXX-XXXX-XXXX-XXXX).
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1313 +/- ##
==========================================
+ Coverage 80.22% 80.33% +0.10%
==========================================
Files 104 104
Lines 14844 14829 -15
==========================================
+ Hits 11909 11913 +4
+ Misses 2935 2916 -19 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall this is the right direction, but all examples should at least compile (or run).
the second one isn't very clear what it's about, and it doesn't compile, which is a sign
that it's incorrect and/or incomplete.
this can be iterated quicker locally with cargo test --doc near-sdk/src/lib.rs
near-sdk/src/lib.rs
Outdated
/// pub fn factorial_mult(&self, n: u32, #[callback_unwrap] cur: u32) -> u32 { | ||
/// n * cur | ||
/// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for task #1312 (NOT in scope of current pr) it can be mentioned that the attribute works by doing the following:
#[no_mangle]
pub extern "C" fn factorial_mult() {
....
let data: ::std::vec::Vec<u8> = match ::near_sdk::env::promise_result(0u64) {
::near_sdk::PromiseResult::Successful(x) => x,
_ => ::near_sdk::env::panic_str("Callback computation 0 was not successful"),
};
let cur: u32 = match ::near_sdk::serde_json::from_slice(&data) {
Ok(deserialized) => deserialized,
Err(_) => ::near_sdk::env::panic_str("Failed to deserialize callback using JSON"),
};
let contract: CrossContract = ::near_sdk::env::state_read().unwrap_or_default();
let result = CrossContract::factorial_mult(&contract, n, cur);
...
with links to corresponding [near_sdk::env] host-functions used
it was also missed that there should've been a link from |
Fixes #1303
Adds documentation for the
callback_unwrap
attribute under the#[near]
macro docs, including:PromiseOrValue
For more details, open the Copilot Workspace session.