Re-add File::from
Closed this issue · 9 comments
In params 0.3, I was using File::from
for integration tests in another library. In params 0.4, this function has been removed, and I am unable to manually instantiate a File
because the fields are private.
I would like File::from
re-added so that I can continue to have mock File
s in my integration tests.
Looks like you're referring to
Lines 95 to 103 in e86eb9e
It still exists: https://github.com/iron/params/blob/master/src/conversion.rs#L96-L103
No, I'm referring to From<multipart::server::SavedFile>
, which was removed here.
@SkylerLipthay I see you removed this block of code mentioning it wasn't intended to be public. Do you have thoughts on this?
Hmm, I believe my intention was to hide multipart
from the public interface entirely, so as to avoid versioning issues. Actually, I think this convoluted interface is a historical remnant of using another form-data library which implemented Drop
to delete the temporary file, but now we have a different way of doing that...
Anyway, I never considered the need to mock File
, but it is a reasonable request. Perhaps the right move here is to destructure the SavedFile
immediately and expose the File
fields directly? After all, I'm already doing this silly bit. This change would involve making the File
fields public, so then it would probably be best to remove all of the getters (path()
, filename()
, size()
, content_type()
). This would be a breaking change, but at first glance I see no other detriments. In fact, this would eliminate the explicit impl Clone for File
and impl Debug for File
@shssoichiro does this sound good? To be clear, the File
interface would be:
pub struct File {
pub path: PathBuf,
pub filename: Option<String>,
pub size: u64,
pub content_type: Mime,
}
Yes, that seems reasonable, especially if it results in less code.
Sounds good. I'm about to fall asleep but I'll fix this and release 0.5 first thing in the morning.
You're so awesome!
0.5.0 published!
@Hoverbear: Thanks for tagging me in this. For some reason I wasn't subscribed to get email notifications for iron/params? Thanks for being so attentive :)
@SkylerLipthay Anything I can do to help. :)