-
-
Notifications
You must be signed in to change notification settings - Fork 168
feat(types): Add custom variant to AttachmentType
#916
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
Changes from 1 commit
cc7b53c
1b42c15
3ad7329
9122269
092f407
a6888fd
42033ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ use std::fmt; | |||||
use serde::Deserialize; | ||||||
|
||||||
/// The different types an attachment can have. | ||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize)] | ||||||
#[derive(Debug, Clone, Eq, PartialEq, Deserialize)] | ||||||
pub enum AttachmentType { | ||||||
#[serde(rename = "event.attachment")] | ||||||
/// (default) A standard attachment without special meaning. | ||||||
|
@@ -23,6 +23,9 @@ pub enum AttachmentType { | |||||
/// the last logs are extracted into event breadcrumbs. | ||||||
#[serde(rename = "unreal.logs")] | ||||||
UnrealLogs, | ||||||
/// A custom attachment type with an arbitrary string value. | ||||||
#[serde(untagged)] | ||||||
Custom(String), | ||||||
tobias-wilfert marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
impl Default for AttachmentType { | ||||||
|
@@ -33,13 +36,14 @@ impl Default for AttachmentType { | |||||
|
||||||
impl AttachmentType { | ||||||
/// Gets the string value Sentry expects for the attachment type. | ||||||
pub fn as_str(self) -> &'static str { | ||||||
pub fn as_str(&self) -> &str { | ||||||
match self { | ||||||
Self::Attachment => "event.attachment", | ||||||
Self::Minidump => "event.minidump", | ||||||
Self::AppleCrashReport => "event.applecrashreport", | ||||||
Self::UnrealContext => "unreal.context", | ||||||
Self::UnrealLogs => "unreal.logs", | ||||||
Self::Custom(s) => s, | ||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -68,7 +72,7 @@ impl Attachment { | |||||
r#"{{"type":"attachment","length":{length},"filename":"{filename}","attachment_type":"{at}","content_type":"{ct}"}}"#, | ||||||
filename = self.filename, | ||||||
length = self.buffer.len(), | ||||||
at = self.ty.unwrap_or_default().as_str(), | ||||||
at = self.ty.clone().unwrap_or_default().as_str(), | ||||||
|
at = self.ty.clone().unwrap_or_default().as_str(), | |
at = self.ty.as_ref().unwrap_or(&AttachmentType::default()).as_str(), |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a .as_ref().map(|a| a.as_str()).unwrap_or_default()
would be even more concise (and avoid the clone
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This .as_ref().map(|a| a.as_str()).unwrap_or_default()
will yield and empty str rather than event.attachment
so not sure we want to change this (at least in this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can still do the explicit unwrap_or
though that one should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
Copy
trait from the enum will impact performance for small operations. Consider keepingCopy
and useCow<'static, str>
for the Custom variant to maintain zero-cost abstractions for predefined types while supporting custom strings.Copilot uses AI. Check for mistakes.