mirror of
https://github.com/Nutomic/ibis.git
synced 2024-12-23 04:41:22 +00:00
less unwrap
This commit is contained in:
parent
8477c07014
commit
de2607e531
5 changed files with 6 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue