@@ -84,7 +84,8 @@ impl<T: Resource> Drop for ResourceInfo<T> {
84
84
}
85
85
86
86
impl < T : Resource > ResourceInfo < T > {
87
- #[ allow( unused_variables) ]
87
+ // Note: Abstractly, this function should take `label: String` to minimize string cloning.
88
+ // But as actually used, every input is a literal or borrowed `&str`, so this is convenient.
88
89
pub ( crate ) fn new (
89
90
label : & str ,
90
91
tracker_indices : Option < Arc < SharedTrackerIndexAllocator > > ,
@@ -149,9 +150,16 @@ pub(crate) trait Resource: 'static + Sized + WasmNotSendSync {
149
150
const TYPE : ResourceType ;
150
151
fn as_info ( & self ) -> & ResourceInfo < Self > ;
151
152
fn as_info_mut ( & mut self ) -> & mut ResourceInfo < Self > ;
152
- fn label ( & self ) -> String {
153
- self . as_info ( ) . label . clone ( )
153
+
154
+ /// Returns a string identifying this resource for logging and errors.
155
+ ///
156
+ /// It may be a user-provided string or it may be a placeholder from wgpu.
157
+ ///
158
+ /// It is non-empty unless the user-provided string was empty.
159
+ fn label ( & self ) -> & str {
160
+ & self . as_info ( ) . label
154
161
}
162
+
155
163
fn ref_count ( self : & Arc < Self > ) -> usize {
156
164
Arc :: strong_count ( self )
157
165
}
@@ -718,8 +726,8 @@ impl<A: HalApi> Resource for StagingBuffer<A> {
718
726
& mut self . info
719
727
}
720
728
721
- fn label ( & self ) -> String {
722
- String :: from ( "<StagingBuffer>" )
729
+ fn label ( & self ) -> & str {
730
+ "<StagingBuffer>"
723
731
}
724
732
}
725
733
0 commit comments