Fix: error type
This commit is contained in:
parent
a0f3a6eaa7
commit
0e38fa8ca7
|
@ -234,6 +234,7 @@ dependencies = [
|
|||
name = "locks"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"ticket_fields",
|
||||
]
|
||||
|
||||
|
@ -296,6 +297,7 @@ version = "0.1.0"
|
|||
name = "patch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"ticket_fields",
|
||||
]
|
||||
|
||||
|
@ -336,6 +338,7 @@ dependencies = [
|
|||
name = "rwlock"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"ticket_fields",
|
||||
]
|
||||
|
||||
|
@ -416,18 +419,18 @@ version = "0.1.0"
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.59"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
|
||||
checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.59"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
|
||||
checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -5,3 +5,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
ticket_fields = { path = "../../../helpers/ticket_fields" }
|
||||
thiserror = "1.0.59"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TrySendError};
|
||||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
|
||||
|
||||
// TODO: Implement the patching functionality.
|
||||
use crate::data::{Ticket, TicketDraft, TicketPatch};
|
||||
|
@ -13,27 +13,35 @@ pub struct TicketStoreClient {
|
|||
}
|
||||
|
||||
impl TicketStoreClient {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, TrySendError<Command>> {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Ticket>, TrySendError<Command>> {
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Ticket>, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
|
||||
pub fn update(&self, ticket_patch: TicketPatch) -> Result<(), TrySendError<Command>> {}
|
||||
pub fn update(&self, ticket_patch: TicketPatch) -> Result<(), OverloadedError> {}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("The store is overloaded")]
|
||||
pub struct OverloadedError;
|
||||
|
||||
pub fn launch(capacity: usize) -> TicketStoreClient {
|
||||
let (sender, receiver) = sync_channel(capacity);
|
||||
std::thread::spawn(move || server(receiver));
|
||||
|
|
|
@ -5,3 +5,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
ticket_fields = { path = "../../../helpers/ticket_fields" }
|
||||
thiserror = "1.0.60"
|
||||
|
|
|
@ -16,25 +16,33 @@ pub struct TicketStoreClient {
|
|||
}
|
||||
|
||||
impl TicketStoreClient {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, TrySendError<Command>> {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Arc<Mutex<Ticket>>>, TrySendError<Command>> {
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Arc<Mutex<Ticket>>>, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("The store is overloaded")]
|
||||
pub struct OverloadedError;
|
||||
|
||||
pub fn launch(capacity: usize) -> TicketStoreClient {
|
||||
let (sender, receiver) = sync_channel(capacity);
|
||||
std::thread::spawn(move || server(receiver));
|
||||
|
|
|
@ -5,3 +5,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
ticket_fields = { path = "../../../helpers/ticket_fields" }
|
||||
thiserror = "1.0.60"
|
||||
|
|
|
@ -15,25 +15,33 @@ pub struct TicketStoreClient {
|
|||
}
|
||||
|
||||
impl TicketStoreClient {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, TrySendError<Command>> {
|
||||
pub fn insert(&self, draft: TicketDraft) -> Result<TicketId, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Insert {
|
||||
draft,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Arc<Mutex<Ticket>>>, TrySendError<Command>> {
|
||||
pub fn get(&self, id: TicketId) -> Result<Option<Arc<Mutex<Ticket>>>, OverloadedError> {
|
||||
let (response_sender, response_receiver) = sync_channel(1);
|
||||
self.sender.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})?;
|
||||
self.sender
|
||||
.try_send(Command::Get {
|
||||
id,
|
||||
response_channel: response_sender,
|
||||
})
|
||||
.map_err(|_| OverloadedError)?;
|
||||
Ok(response_receiver.recv().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("The store is overloaded")]
|
||||
pub struct OverloadedError;
|
||||
|
||||
pub fn launch(capacity: usize) -> TicketStoreClient {
|
||||
let (sender, receiver) = sync_channel(capacity);
|
||||
std::thread::spawn(move || server(receiver));
|
||||
|
|
Loading…
Reference in New Issue