Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[db] Add track_caller to agdb_derive #1243 #1249

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions agdb/src/db/db_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ impl<T: Into<DbValue>> From<Vec<T>> for DbValue {
impl TryFrom<DbValue> for Vec<u8> {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.bytes()?.clone())
}
Expand All @@ -476,6 +477,7 @@ impl TryFrom<DbValue> for Vec<u8> {
impl TryFrom<DbValue> for u64 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
value.to_u64()
}
Expand All @@ -484,6 +486,7 @@ impl TryFrom<DbValue> for u64 {
impl TryFrom<DbValue> for u32 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.to_u64()?.try_into()?)
}
Expand All @@ -492,6 +495,7 @@ impl TryFrom<DbValue> for u32 {
impl TryFrom<DbValue> for i64 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
value.to_i64()
}
Expand All @@ -500,6 +504,7 @@ impl TryFrom<DbValue> for i64 {
impl TryFrom<DbValue> for i32 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.to_i64()?.try_into()?)
}
Expand All @@ -508,6 +513,7 @@ impl TryFrom<DbValue> for i32 {
impl TryFrom<DbValue> for f64 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.to_f64()?.to_f64())
}
Expand All @@ -516,6 +522,7 @@ impl TryFrom<DbValue> for f64 {
impl TryFrom<DbValue> for f32 {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.to_f64()?.to_f64() as f32)
}
Expand All @@ -524,6 +531,7 @@ impl TryFrom<DbValue> for f32 {
impl TryFrom<DbValue> for String {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
Ok(value.string()?.clone())
}
Expand All @@ -532,6 +540,7 @@ impl TryFrom<DbValue> for String {
impl TryFrom<DbValue> for bool {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
value.to_bool()
}
Expand All @@ -540,6 +549,7 @@ impl TryFrom<DbValue> for bool {
impl<T: TryFrom<DbValue, Error = DbError>> TryFrom<DbValue> for Vec<T> {
type Error = DbError;

#[track_caller]
fn try_from(value: DbValue) -> Result<Self, Self::Error> {
let db_values: Vec<DbValue> = match value {
DbValue::VecI64(v) => Ok(v.into_iter().map(DbValue::from).collect()),
Expand Down
6 changes: 6 additions & 0 deletions agdb_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,24 @@ pub fn db_user_value_derive(item: TokenStream) -> TokenStream {
});
let tokens = quote! {
impl agdb::DbUserValue for #name {
#[track_caller]
fn db_id(&self) -> Option<agdb::QueryId> {
#db_id
}

#[track_caller]
fn db_keys() -> Vec<agdb::DbValue> {
vec![#(#db_keys.into()),*]
}

#[track_caller]
fn from_db_element(element: &agdb::DbElement) -> std::result::Result<Self, agdb::DbError> {
Ok(Self {
#(#from_db_element),*
})
}

#[track_caller]
fn to_db_values(&self) -> Vec<agdb::DbKeyValue> {
vec![#(#db_values),*]
}
Expand All @@ -113,6 +117,7 @@ pub fn db_user_value_derive(item: TokenStream) -> TokenStream {
impl TryFrom<&agdb::DbElement> for #name {
type Error = agdb::DbError;

#[track_caller]
fn try_from(value: &agdb::DbElement) -> std::result::Result<Self, Self::Error> {
use agdb::DbUserValue;
#name::from_db_element(value)
Expand All @@ -122,6 +127,7 @@ pub fn db_user_value_derive(item: TokenStream) -> TokenStream {
impl TryFrom<agdb::QueryResult> for #name {
type Error = agdb::DbError;

#[track_caller]
fn try_from(value: agdb::QueryResult) -> std::result::Result<Self, Self::Error> {
use agdb::DbUserValue;
value
Expand Down