Add API docs for Amount type#710
Conversation
3937e69 to
c293ef4
Compare
There was a problem hiding this comment.
I have looked at the generated doc. Looks good. Only weird thing is the constructor doc. This was mentioned for TxBuilder here promarcos as well hence I believe its a known thing. Besides this I could go ahead and approve.
|
Yeah I agree we should look at exactly where to put the docstrings. Let me confirm where is best and I'll push the changes if there are any. |
|
I have played around with docstring placement. I think the best place to have the general type definition is on the Example/// This is the definition used on the struct.
#[derive(Clone, Debug, uniffi::Object)]
pub struct Script(pub BdkScriptBuf);
/// This is the definition used on the impl block.
#[uniffi::export]
impl Script {
/// This is the docstring for the constructor.
#[uniffi::constructor]
pub fn new(raw_output_script: Vec<u8>) -> Self {
let script: BdkScriptBuf = raw_output_script.into();
Script(script)
}
/// This is a docstring for a method.
pub fn to_bytes(&self) -> Vec<u8> {
self.0.to_bytes()
}
}Resulting API docs: |
c293ef4 to
807fd9f
Compare
|
I see. When using the actual JVM docs this is the best configuration. My autocomplete was showing the constructor docs, but that's more of an IDE quark. We should go with the style you have here |
|
ACK 807fd9f |
This comment was marked as resolved.
This comment was marked as resolved.
|
I have just seen from testing and docs that using the All good here! |
|
@rustaceanrob @ItoroD good points. I also wanted to make sure I got correct behaviour on my IDE and decided to go one step further in my digging. Here is what I found after testing a bunch of stuff. SetupI used the /// These are the type-level API docs declared on the struct block.
#[derive(Debug, PartialEq, Eq, uniffi::Object)]
pub struct Address(BdkAddress<NetworkChecked>);
/// These are the API docs declared on the impl block.
#[uniffi::export]
impl Address {
/// These are the API docs declared on the default constructor.
#[uniffi::constructor]
pub fn new(address: String, network: Network) -> Result<Self, AddressParseError> {
let parsed_address = address.parse::<bdk_wallet::bitcoin::Address<NetworkUnchecked>>()?;
let network_checked_address = parsed_address.require_network(network)?;
Ok(Address(network_checked_address))
}
/// These are the API docs declared on an alternative constructor.
#[uniffi::constructor]
pub fn from_script(script: Arc<Script>, network: Network) -> Result<Self, FromScriptError> {
let address = BdkAddress::from_script(&script.0.clone(), network)?;
Ok(Address(address))
}
/// These are API docs declared on a method.
pub fn script_pubkey(&self) -> Arc<Script> {
Arc::new(Script(self.0.script_pubkey()))
}Results
|
|
@ItoroD about the constructors: Yes uniffi doesn't allow for constructor overloading, and so only one standard constructor can be created per type. Rust usually uses the The companion object has always been a little quirk of Kotlin that I don't know was ever that clear, and I have even heard Andrey Breslav say it was one of the things he regrets introducing (complexity that didn't add much). They're really just static methods on the type. Pardon me going off on this if you're super familiar with Kotlin idioms I just wasn't sure. |
Yeah, in my experience this is the first thing that comes up when typing normally? Because the hover functionality to pull up the struct-level documentation exists, I think it is fine to leave it how we have it. In a way it makes sense, for most people they just want to know how to make an Electrum client for instance. The description of the client can be found for the curious by hovering. |
That makes sense. 👍 |





Sorry I was too quick to merge #708! My bad.
This fixes that.
See https://docs.rs/bitcoin/latest/bitcoin/struct.Amount.html for details.