Skip to content

Commit

Permalink
Improve find_by_uri return type to return a reference (like other fin…
Browse files Browse the repository at this point in the history
…d functions). Improve docs examples
  • Loading branch information
vemonet committed Jan 3, 2024
1 parent a74e51e commit 121f412
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version.workspace = true
edition.workspace = true
description.workspace = true
readme.workspace = true
license.workspace = true
license-file.workspace = true
keywords.workspace = true
categories.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion lib/docs/use_javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ Install the `npm` package (use `yarn` or `pnpm` if you prefer) to use it from yo

```bash
npm install @biopragmatics/curies
# or
pnpm add @biopragmatics/curies
# or
yarn add @biopragmatics/curies
```

## 🟢 Use it in a NodeJS environment

There are multiple methods available for creating or importing converters:

```ts
```javascript
import {Record, Converter, getOboConverter, getBioregistryConverter} from "@biopragmatics/curies";

async function main() {
Expand Down
2 changes: 2 additions & 0 deletions lib/docs/use_rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
You can use the Rust crate to work with CURIEs: import converters, compress URIs, expand CURIEs.

```rust
extern crate curies;
use curies::{Converter, Record, sources::get_bioregistry_converter};
use std::collections::HashSet;

Expand Down Expand Up @@ -48,6 +49,7 @@ rt.block_on(async {
You can also build a `Converter` from scratch:

```rust
extern crate curies;
use curies::{Converter, Record};
use std::collections::HashSet;

Expand Down
4 changes: 2 additions & 2 deletions lib/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl Converter {
}

/// Find corresponding CURIE `Record` given a complete URI
pub fn find_by_uri(&self, uri: &str) -> Result<Arc<Record>, CuriesError> {
pub fn find_by_uri(&self, uri: &str) -> Result<&Arc<Record>, CuriesError> {
match self.trie.find_longest_prefix(uri.bytes()) {
Some(rec) => Ok(rec),
None => Err(CuriesError::NotFound(uri.to_string())),
Expand Down Expand Up @@ -399,7 +399,7 @@ impl Converter {
.find_map(|synonym| uri.strip_prefix(synonym))
})
.ok_or_else(|| CuriesError::NotFound(uri.to_string()))?;
self.validate_id(id, &record)?;
self.validate_id(id, record)?;
Ok(format!("{}{}{}", &record.prefix, self.delimiter, id))
}

Expand Down

0 comments on commit 121f412

Please sign in to comment.