1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-21 19:31:09 +00:00

less unwrap

This commit is contained in:
Felix Ableitner 2023-11-15 01:32:46 +01:00
parent 8477c07014
commit de2607e531
5 changed files with 6 additions and 5 deletions

View file

@ -20,7 +20,7 @@ pub struct Accept {
impl Accept {
pub fn new(actor: ObjectId<DbInstance>, object: Follow) -> MyResult<Accept> {
let id = generate_object_id(actor.inner().domain().unwrap())?;
let id = generate_object_id(actor.inner())?;
Ok(Accept {
actor,
object,

View file

@ -22,7 +22,7 @@ pub struct Follow {
impl Follow {
pub fn new(actor: ObjectId<DbInstance>, object: ObjectId<DbInstance>) -> MyResult<Follow> {
let id = generate_object_id(actor.inner().domain().unwrap())?;
let id = generate_object_id(actor.inner())?;
Ok(Follow {
actor,
object,

View file

@ -25,7 +25,7 @@ pub struct Update {
impl Update {
pub fn new(actor: ObjectId<DbUser>, object: ObjectId<DbArticle>) -> MyResult<Update> {
let id = generate_object_id(actor.inner().domain().unwrap())?;
let id = generate_object_id(actor.inner())?;
Ok(Update {
actor,
object,

View file

@ -21,7 +21,7 @@ pub struct DbArticle {
impl DbArticle {
pub fn new(text: String, attributed_to: ObjectId<DbInstance>) -> Result<DbArticle, Error> {
let ap_id = generate_object_id(attributed_to.inner().domain().unwrap())?.into();
let ap_id = generate_object_id(attributed_to.inner())?.into();
Ok(DbArticle {
text,
ap_id,

View file

@ -3,7 +3,8 @@ use url::{ParseError, Url};
/// Just generate random url as object id. In a real project, you probably want to use
/// an url which contains the database id for easy retrieval (or store the random id in db).
pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
pub fn generate_object_id(domain: &Url) -> Result<Url, ParseError> {
let domain = domain.domain().unwrap();
let id: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(7)