Read CSV Files with Rust CSV Crate πŸ¦€πŸ“¦ Rust Programming Tutorial for Developers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys my name is Trevor Sullivan and welcome back to my video channel thank you so much for joining me for another video in our rust programming tutorial series now the topic for this particular video is going to be some data parsing using the CSV syntax previously in my rust programming playlist I actually covered how to use the survey library in order to parse Json data but this time we're going to be taking a look at CSV instead now we used survey with Json previously but this time we're actually going to look at some of the core capabilities of parsing csvs without using survey but the CSV package or crate on crates.io also does support integration with surday as an optional feature so if you want to use the survey route and use the standard deserialization capability into a data structure you're more than welcome to do that but if you just want to read a CSV file as what it is which is basically just a bunch of columns and rows then you can do that without having to include the survey package as well so if you just want to use CSV as a dependency in your application without including survey you're more than welcome to do that and we'll take a look at both different approaches in order to parse rcsv data here now if you want to grab some sample data up front when you're working through the sample feel free to I'm just going to go ahead and create a really simple CSV file for this particular demo just so that we can see the process of creating and tweaking the CSV file format and just kind of customizing how exactly we read it now they do have really good documentation in the CSV crate so check out the tutorial module right over here as well as the cookbook module right here that gives you kind of a task oriented approach to using the CSV crate here but it's actually a really simple package so once you've run through a couple of iterations tons of utilizing the CSV package everything should be pretty familiar to you now when you're reading records from a CSV file typically you're probably going to read those as utf-8 string values however there could be some situations where certain byte sequences are not interpretable as utf-8 characters and you need to just read the raw bytes of data from the CSV file so you have two different mechanisms to interpret the data from a CSV we're going to be mainly looking at string records just because a lot of CSV files are going to have string related data or data that can be at least represented as a string and then perhaps coerced into a different primitive data type but you do also have the option to interpret those CSV records as just a raw stream of bytes as well now you can read CSV data from a variety of data sources the way that the CSV crate has implemented reading data is actually really intuitive so if we take a look at this reader data structure that's directly exported from the root to the CSV crate you'll see that it implements a function here that allows you to read the individual records and this is actually created from a builder but when you use this function here called from reader or from path the from path is kind of a helper that allows you to read from a file on the local file system but if you take a look at how to read from a reader here it actually allows you to read from any type that implements the reader or read trait from the standard i o interface so this is a really convenient way to read a data it could be from a stream of bytes it could be from a file handle it could be from all sorts of different data sources so this gives you a lot of flexibility as far as where the actual CSV data is coming from now there's a couple of different ways to actually create the reader you can just go out to the reader here and say create a reader from a particular path you can specify the file system path that you want to read from and then you can immediately start to just iterate over the different records by using the records function here which returns an iterator across all of the individual records in the CSV file and then within each of those you can go ahead and just grab the individual fields from those records by calling the get function so if we take a look at the record type over here let's go down to structs and then go to string records and there's a get function here that we can use to index into the different Columns of each row so if your CSV has maybe five rows or five sorry five columns not rows then you can reference those columns from 0 through 4 to grab the different values if you decide to to use the survey integration though you can actually deserialize the individual rows to a custom user-defined data structure I have a separate video in my rust playlist that covers how to define structs and struct methods and things of that nature also if you want to learn more about survey specifically you can go back to my video on Json so you can use survey to deserialize Json objects into well-defined rust data structures as well but this time we're going to be doing the same thing with CSV but if you don't decide to go to the survey route you can always use this get function here to get a specific index of a column from a particular Row in your CSV file there's also a bunch of other kind of helper functions in here as well like getting the length of the record you can trim truncate get a particular position things like that so feel free to take a look at those but we're just going to look at the essentials which is basically iterating over records deserializing into a data structure getting individual columns from a particular record and there's also some customization options that we have on the reader here so one way is to just use the reader here and do from path and that'll give you a reader object that you can read records from but if you need to do any kind of more advanced customization on the CSV parser then there's another data type you're going to want to look at or a structure I should say and that's called the reader Builder and the reader Builder basically before you get a reference to a specific reader this reader Builder allows you to call a bunch of helper functions that allow you to customize the mechanism that the reader uses to parse the file for example we've got things like the double quote option here so if we have double quotes around the individual field values in our csve file then we can specify that there are double quotes I think by default it is enabled but it can be disabled as well and then we also have things like setting a custom delimiter here as you probably know every CSV file can look a little bit different even though the CSV suffix stands for com separated values you might have a tab character that is used as the separator or delimiter you might also have something like the pipe character the vertical pipe character that's used as a delimiter and so this delimiter function on the reader Builder allows us to configure a custom unsigned 8-bit integer that represents an individual character that's going to be interpreted as the field delimiter for each of the rows in your CSV file we also have the ability to specify a comment value as well so this is going to be the character that begins the record so if maybe you have like a individual dash at the beginning of a record that can be used to ignore a particular row because that would be considered a comment to the parser rather than being an actual data row so you can customize which kind of character you want to use for that as well there's also the ability to specify the custom quote character so I'm obviously most common CSV files are gonna probably use a double quote character to indicate the delimiters around the individual field values but you can also override that by using the quote function here so anytime that you need to kind of customize the behavior of the parser you'll want to go into the reader Builder struct and then use that Builder with the helper functions to chain the configuration files or configuration options together before you actually construct the reader itself once you've customized the reader Builder though you can once again just call from path or from reader on the reader Builder type here and that will ultimately give you a reference to a reader that you can use to read the records from the CSV using the records function all right so we're going to go ahead and take a look at how to implement this also I did want to just really quickly point out that when it comes to the reader here when we take a look at the records I think it's the record uh let's see I think it's the reader type here so we have this deserialized function that we use in order to deserialize into a custom data structure this is kind of the implementation of the survey package and if we take a look at this trait boundary here on the generic type D that's being passed into the deserialized function here the deserialized owned trait that's actually coming from the survey package it's probably a little bit small on your screen just because it's a tool tip in Firefox here but if I hover over that it's actually a reference to the survey d d e module and then deserialize owned is the actual name of the trait under that module so once that's implemented this allows the deserialize function in the CSV crate to actually call into the survey functionality and deserialize into a custom data structure and again all this kind of stuff is covered in the Excellence documentation here so if you would prefer to read the doc documentation rather than watch this video tutorial you're more than welcome to do that as well so we're going to go ahead and spin up a sample project and actually go ahead and create a really simple basic CSV file and then we'll just parse that and kind of take a look at how some of these different functions work but before we get into that I just wanted to invite you to support this channel because I'm an independent content creator your support goes directly towards helping me to produce new videos on my channel whether it's rust or other related topics like database platforms so please subscribe to the channel also check out the pinned comment below where I have a link to my Amazon storefront which is an affiliate program that helps to fund this channel as well it helps me to publish free videos for you so that it doesn't have to be a paid Subscription Service also leave a like on the video and leave a comment down below and let me know what you learned from this video and what other kind of topics you're interested in seeing on my channel alright so let's go ahead and jump in and actually create create a new project now again as I mentioned in most of my videos if you go back to the first video in my rust tutorial playlist which is featured right on my channel page I have a Linux virtual machine set up here that I have vs code connected to remotely so I'm using the remote SSH extension for vs code in order to connect out to that virtual machine you can certainly develop locally on Windows or Mac OS X as well but in general I just prefer to do my development on a Linux VM because I can just rapidly rebuild that with lexd I've also got a really cool tutorial series on Lex D so feel free to check out those videos and how to use lexd to spin up virtual machines on a Linux server as well so in here we're just going to create a new project folder we'll call it CSV test for now then we'll do Ctrl K Ctrl o and open up that directory inside of our editor here also you will need the rust analyzer extension I've already got that installed in all of my virtual machine environments that I use for rust development here so once vs code is connected you can always install that extension into the remote environment and that'll give you Auto completion and a lot of linting help and things like that as well so what we're going to do for starters is just initialize a new project with cargo init right here and then in cargo.tomo we don't have any dependencies so of course we need to include the CSV dependency over on the crates.io registry here if you just do a search for CSV generally this package is going to come up first here and it is pretty popular it's got over 35 million approaching 36 million downloads here and it is pretty well up to date there's 79 historical versions and the author is doing a really great job of just maintaining this library and keeping it up to date so we're going to be installing this also there's no additional features when we do cargo add CSV you'll notice that there's no optional features when we've done videos on things like Tokyo or small or other crates you'll oftentimes see that there's optional features that you can enable or even survey for that matter but in the case of CSV here there are no optional features that you need to worry about so you don't need to do cargo ad and then specify the features parameter to enable those you get all the functionality of the CSV crate and then what we'll do is go over into our main.rs file here get rid of that hello world right there let me go into zen mode here to clean up our screen real estate and now we can start to plug into the CSV crate now the other thing I'm going to do is just create a sample file here so let's create a file in our project at the root because typically I am executing it at the root with cargo run and I'll just call this data.csv and you can come up with whatever kind of sample data that you want to I found some sample data sets on GitHub that cover things like blood pressure for different genders there's all sorts of you know vehicle data out there you can even request data from your local government as well through open records requests so there's lots of different ways to get date access to some raw CSV data that represents kind of real world things but for now I'm just going to go ahead and create something called manufacturer model and then and we'll just use these three individual fields to represent Vehicles right common makes and models so we'll just do maybe a BMW 335i and say the VIN is 789 we'll do a Chevrolet or let's see what Nissan on Rogue and do 567 and then we'll do a Tesla Model X and that'll be serial one two three so this is our very Advanced CSV file here we are going to use commas for starters here just to keep things relatively simple but we'll take a look at how to use that reader Builder type in order to customize the behavior of parsing the CSV as well using different options so back in main here the first thing we want to do is call into CSV here and create one of these readers and so you'll just go into CSV and then grab reader or you can do a use statement and say I want to use the reader struct right here and then we don't need to worry about prefixing it and then we can go ahead and call from path and specify the path to a file on the local file system and so let me create a variable called file name and we'll set that to data.csv and then I can always shadow that variable or overwrite that variable with a new value if we need to and so I'll just pass that in to this function right here and we'll say let my reader as a variable equal the result now this is going to give you a typical result object here that wraps either the reader with the file as the backing store for the reader again there's lots of different implementations of the read trait in the standard i o namespace but there's also the error here so if maybe a file doesn't exist like maybe if we try to point to data2.csv that doesn't actually exist on the local file system then we'll probably get an error so let's go ahead and try to see if we get an error from this so we'll say if my reader dot is error then we'll say print line failed to read CSV file path probably doesn't exist or you don't have permission okay so let's go ahead and run that we'll do cargo run we'll compile our dependencies there and as you can see it says failed to read CSV and that's because we specified a path that doesn't exist right so now if we change the file to data.csv you can see that our program runs just fine we skip over this if statement here because it's working fine and the other thing we can do is to just exit out so I think we can just do standard process and then exit and we'll just exit with some non-zero exit code directly if there is an error so that way any code that we use after the fact is is not going to run because we are exiting our process right here so if an error occurs we just want to exit immediately otherwise we'll go ahead and write some code as far as what we want to do with the CSV file right after that so for starters here we can just say my reader dot uh Records I think so let's go ahead and oh we actually need to grab the results so let's do my reader dot unwrap and I'll say let reader and I'm actually going to re-change this to result because that's the result object and then we'll do results.unwrap and assign that to my reader because that's the actual reader itself and then we can do MyReader dot records and this is going to grab the iterator across all of the individual records so typically what you're going to probably want to do is just to do a for Loop to iterate over all the records in that list and so we'll say four record in my records go ahead and do something now we're also getting this error here saying that we cannot mutate immutable variable because we didn't declare the reader as mutable so let's do mute reader here on line 11 and turn my reader into a mutable variable and so then what we'll do is inside of our for Loop here we want to do something with the individual field so for each record we're going to iterate over in the data.csv here we're going to start with record number one then we'll go to record number two and finally record number three and what do we want to do with each of these records well we can reference these individual Fields because we know the structure of the CSV file here we can we know that the field zero or the very first field index 0 is going to be manufacturer one is going to be model and two is going to be Vin because we have a zero based index so what we can do is say your are manufacturer is and then insert a placeholder for the manufacturer so now we need to do is go to the record that we have right here and actually attempt to retrieve the value of the first field or the First Column inside of that record so the way that we do that is grab the record here which is wrapped in a result so we'll do record dot unwrap and then we'll go ahead and call the get function here which is on the record type so again if we go over to the CSV documentation take a look at the data structures here and go to the record structure so it's going to be a string record right here and we have the get function and this allows us to retrieve a field value at that particular index so we'll say I want to get the zero with index here and that's going to give us an option type so we actually need to unwrap the final value from that and that should show us what the car manufacturer is so now if we do cargo run you can see that we print out each from each record in the CSV file we just get the manufacturer value we can also use the other fields in there though so we could say your car model is X and then we'll go ahead and grab field number one and your car then is field number two right so what we're going to go ahead and do is actually take record dot unwrap right here and just assign it to a variable because we're actually using it multiple times and that's causing a move operation to occur so we're losing access to that record so I'm just going to say let car equal record dot unwrap and then we should be able to do car dot get on each of these fields here and yep that's going to compile just fine so now we can do cargo run and we are grabbing the manufacturer model in Vin independently in each of these records here so as you can see it's really really simple to read CSV data now one of the things you might have noticed is that the very first row of our CSV file here didn't get printed out so it doesn't say your car manufacturer is manufacturer it just tells us the actual field values here because it's only looking at rows two three and four and not the very first row however some of the I just realized I have a little typo there so call it manufacturer but it didn't matter because we were indexing by the ID or the index number not the actual field name when we go to use survey though that's where we'll actually deserialize the file based on the field name instead of the field index and so it's much more important when we're using survey but anyways now that we've got that fixed you'll notice that this very first row here is not being printed out and that's because the reader by default is going to assume that there is a header Row in the CSV file and it's going to skip over that header row now if you use the reader Builder you can actually specify that your reader should not have a header row and so you can actually Force the CSV parser to interpret that very first header row as a data record just like the remainder of the records in the CSV file so instead of going directly to the reader struct here and calling from path we're going to switch over to actually using the reader Builder instead so that we can apply some Advanced customizations to our CSV parser so what we'll do is import the reader Builder type so we'll put semi or um we'll put curly braces around this because we need to actually grab multiple Imports here so we want reader and reader Builder this time and now we're going to create a builder before we create the reader itself so to create the Builder we'll just say let Builder equal the reader Builder and then we'll go ahead and just new it with a new function here and then we can use the period operator here to take that instance of the reader Builder and call some customization functions on it for example if we wanted to specify that there are no double quotes I think by default it is looking for double quotes but we can just say well I know I don't have double quotes so just don't bother with that we could also specify a comment here and take in an option u8 so what we could do is just specify a binary value here of let's say a what's this our slash so we're going to say if it starts with a dash here then we'll go ahead and specify that that's going to be a comment we could also chain something else and say has headers is false and so that'll Force the reader to include the header row as an actual Theta row and there's other helpers in here as well so we could do something like quoting rules or set the custom quote character if we wanted to we could even set a custom Terminator so if we want to override the line termination character instead of using a new line character we could actually specify that it is something else instead so a lot of different options depending on what the exact format of your CSV file looks like so now that we've got this Builder right we've got this mutable reference to a builder but now instead of directly instantiating the reader from the reader struct we want to go to this Builder and specify that we want to create a reader using the Builder's customized options so what we'll do is go to the Builder and again this is all in the documentation so I just want to show you where you can look this up so under the data structures in the CSV crate here we'll go down to the reader Builder and again we have the from path and from reader so from path is what we're going to use again but we're going to call from path on the reader Builder not the reader right so what we're going to do is say Builder Dot from path and then pass in our file name and I'll just comment outline number six for now and we'll say let the result equal Builder from path and then we also need to make sure that we unwrap the results there actually we're going to check the error on it so I'm not going to unwrap it right here and that'll allow this error handling code to be maintained there now one other thing you can see is temporary value dropped while borrowed so what we're going to do is just start by instantiating the Builder and then we'll do Builder Dot and then we can customize all of these additional values but we do need to make the Builder mutable because we are changing some of the options that are internal to the state of that Builder instance right here so if you get that error saying temporary value dropped while borrowed then just separate these lines so that you instantiate the reader Builder and then you apply the method chain to customize its options all right so let's go ahead and give this a try so we should include the header row as a data row this time we should also have a custom comment prefix character so any lines that have a dash ahead of them should not be included as data rows and then we also specified that we don't have double quotes but I don't think that that's going to functionally change anything with our file since we already don't have double quotes anyway so let's give this a run here and as you can see it works pretty much the same as just doing a standard reader with a couple of exceptions so number one is you can see right here that we have our car manufacturer is manufacturer your car model is model your Carvin is Vin and that's again because the very first data row that we have here is being interpreted as a data row rather than a header row so we're telling the CSV parser that we don't actually have a header Row in our file so therefore use it or interpret it as a data row right now what else did we customize here well we also specified a comment so if we wanted to Omit a certain row like the Nissan Rogue right here we should be able to put a dash ahead of that and now when we run this you can see that the Nissan Rogue vehicle is completely omitted from the record result that we get back so down on line number 16 where we call myreader.records this method call to records is not returning it's not including the Nissan Rogue row because it was prefixed with a dash which effectively commented out or ignored that particular data row so you can use that with any character that you want you could make it an asterisk if you want you know we could change that Dash to an asterisk instead do cargo run and that effectively works the same way so it's really up to you what kind of common character you want to use if you are going to specify one in the reader Builder configuration so feel free to check out the documentation for the reader Builder and look at some of the other helper functions that you have to customize the parser for CSV all right so now we've taken a look at the reader type we also took a look at the reader Builder let's go ahead and Tack on survey so we're going to include survey as a dependency which up to this point we haven't done we've only used the CSV package and any direct dependencies that the CSV package has or crate I should say so if we check out the CSV package on crates dot IO and take a look at the dependencies here you can see that CSV core is a dependency itoa and Ryu and survey is actually also a dependency but right now surday is actually a transitive dependency because if we take a look at our cargo.tomo file here we don't actually have surday declared as a direct dependency instead it's a transitive dependency because it's a sub dependency of a dependency that we explicitly specified within our rust project file here so what we want to do is for starters do a cargo add survey here and this is just going to install the default feature so now CSV didn't have any features that were optional but surday does and generally when you're working with surday I would say probably 95 or maybe even north of 95 percent of the time you're going to end up using the derive feature of survey because this allows you to annotate your data structures and individual struct fields to customize the way that survey behaves again if you go back to my video on survey with Json we actually covered how some of those attribute operations work so that you can customize things like field names and convert things like that convert diff between different cases like camel case or Pascal case or snake case and things like that so we're going to go ahead and include surday here and once we've done that we also want to say add the feature called derive so we'll do cargo add survey features derive and now we should see the little blue plus sign next to derive and standard or a survey derive that actually might be green on some other systems but I think the uh color theme that I'm using in vs code here is just making green show up as kind of a light blue color there so I'm not entirely sure what that should be but I think it might be green all right so now back over in our application here let's come up with a data structure that actually represents the data rows in our project here so what we're going to do for starters is just eliminate this has headers thing because we don't care about that we want to make sure that we include the header row as actual headers but the double quote thing we can ignore that the comment thing we can ignore that as well because I don't think we have any Fields commented out right now no we don't so that should take us back more or less to what the default configuration looks like so now what we're going to do is come up with the data structure to represent our kind of schema here so we have manufacture model VIN so we'll just do a struct car or you could do something like vehicle maybe and then we're going to define the individual field so we'll have manufacturer and rust prefers that we use snake casing so we'll say manufacture is a string type we'll say model is a string type as well and then let's do lowercase Vin is going to be a string type as well now in order for us to be able to de-serialize our CSV data rows as the vehicle data structure here we actually need to annotate this with a derive attribute so we're going to say derive and then we're going to use survey and deserialize we have two different traits here so if we wanted to write CSV data we would need to be able to take the data structures in memory and write those or convert them as a CSV interpretation but for now we're just reading data in this particular video so we only need to deserialize or translate the CSV structure into the in-memory representation of a vehicle so we'll say deserialize and also include debug here in case we want to do debug output of our custom data structure here and we're getting some warnings saying those are never red we don't really care about that for now because eventually we are going to read those but now we need to customize our code a little bit down here because instead of just iterating over the records we actually need to call the other function on the reader type here which is called the deserialize function so let's go back to the CSV root go down to data structures go to the reader because we're still going to have a reader that points to a file but the only difference is that instead of calling the dot records function right here to get the string records iterator we're going to be calling the deserialize function instead and this is what references the deserialize owned trait in survey and allows the CSV crate to actually interpret our CSV data rows as individual instances of our custom user-defined data structure so what we're going to do is just include as you can see in this example down here debug and deserialize you don't really need debug but we're just going to include that and then we also can use the survey attribute here in order to rename fields and this is really important because if you have any differences between these headers and the struct fields that you've defined for your custom data structure then the interpretation or the deserialization process is going to fail so right now if the only thing that we did was change this to dot d serialize and we grabbed a record you're going to see that it's an unknown type here because we have to annotate exactly what the record is so in this case we're going to unwrap the record as a car type and so it's actually a vehicle type I forgot I changed it to vehicle so we're going to interpret the record as a vehicle and then by the by by reference the compiler is able to determine that the result here should be wrapping a vehicle and error because we explicitly declared this as a vehicle down here when we unwrap the underlying value from the results so we don't have to annotate the record up here we can actually just annotate the car where we unwrap it and then the rust compiler knows by inference what that is supposed to be in the result type there so if that's the only thing that we changed here let's also clean this up because we don't have any direct references to reader we're just using the reader Builder to create the reader so we don't actually have to reference that type um actually we do because now it's saying that we don't have a method down here actually no that's because we're changing to our data structure yeah so the other thing we need to do down here is once we turn the car from a record just a generic string record where we just have the field indices 0 1 and 2. now we actually want to go grab the field values from the struct instance so now we can do car dot manufacturer we can also do car dot model and we can do car dot then but do you think that this example is going to work right we're referencing manufacture model in Vin we've got deserialize here but let's try this and see what happens so let's just do cargo run here and we should get a panic I think in our results yeah sure enough so our main thread panicked and the exact reason that this is happening is because it says missing field manufacturer and I want you to pay really close attention to the casing of that manufacturer field because on our custom data structure here we have a more rustic style uh snake case where we have a lowercase leading character but if you look at our CSV file you know this could have come from some other location like an external vendor so we might not have direct control over the schema and so in this particular case we have a capital M as the prefix for the field headers so what we need to do is actually take advantage of the survey features we can head over to surday.rs where the documentation is for the survey crate and if we take a look at field attributes here so this is how we can customize the behavior of individual struct Fields during the deserialization process and what we can do is tack on these survey attribute here and specify that we want to rename the field as something else so we can rename the capital manufacturer as a lowercase manufacturer instead and so what we're going to do is just add this on and that'll allow us to successfully read the file so let's go ahead and add the survey attribute here and you can see that we actually have the ability to serialize and deserialize as different field names so if we wanted to convert this file from using capitals to lowercase we could actually say I want you to deserialize it as a capital M manufacturer but I want you to re-serialize it using a lowercase M manufacturer that's more consistent with our rust code so it's really up to you what route you want to go with that but we'll just say rename and then deserialize and set that to manufacturer and then I'll just do alt shift down arrow to duplicate that line a second time and we'll just use that same syntax here for model and we'll also customize Vin which is all in capital letters right there all right so now that we have specified to the survey Library what our deserialization field names should be let's go ahead and try this again we'll do a cargo run and as you can see everything looks perfect here we're reading the individual data rows we're not including the header row because we commented out the has headers there but everything else is working fine now if we had a CSV file that was a little bit different let's say that maybe we replace let's do a control h here and replace commas with pipe characters and we'll do Ctrl Alt Enter in vs code to just do a replace all in this file so now this is probably going to fail again because we no longer have a valid CSV file right by default the CSV package or create is looking for a comma separator but right up here again because we're trying to deserialize with surday it's saying it can't find a manufacturer field at all so what we're going to do is just customize our reader Builder once again if we head over to the docs for that reader Builder type in the CSV docs here over at docs.rs you can see that we've got a delimiter here and the delimiter just allows us to specify a byte value that indicates the character we want to use as the field delimiter so in this example right down here they overrode the delimiter to a semicolon but we're going to be using the pipe character instead so back over in our code right here we're just going to go up to the line where we create the Builder and we'll tack on another method to our method chain specify our delimiter as a binary let's say or a bytes value I should say which is going to be a pipe character go ahead and save that do a cargo run and once again our file is being interpreted correctly so as you can see there's a bunch of customization options that we have here we have the option to use survey to do the decertilization if we want to into a custom user-defined data structure or we can just use that get function on the individual records to grab the fields or columns from those CSV data rows by using the field index number instead of the field name personally I like the deserialization mechanism because it does allow me to make my code a lot more readable where I can actually specify what the field name is on the actual data structure and as you can see we also got the auto completion here because rust knows that we're dealing with a vehicle type here so we can auto complete those field names directly here in our code so I prefer that approach but it does require just a little bit more coding here in order to implement those custom data structures and if the input form mat of your CSV ever changes then you'll want to make sure that you come update your data structure and deserialize any additional fields that are provided in your Source data so that's pretty much everything I had for this video again thank you so much for watching I hope that you learned something new again please support the channel by liking commenting subscribing and finally going to my Amazon storefront and just purchase some common household items through there I've got a whole bunch of different things that you can purchase through that Amazon storefront it's in the pinned comment or the description down below thanks so much for your support and we'll see you in the next video take care
Info
Channel: Trevor Sullivan
Views: 4,202
Rating: undefined out of 5
Keywords: rust, rustlang, rust developer, rust programming, rust software, software, open source software, systems programming, data structures, rust structs, rust enums, rust coding, rust development, rustlang tutorial, rust videos, rust programming tutorial, getting started with rust, beginner with rust programming, rust concepts
Id: 9w3rVqsdLRE
Channel Id: undefined
Length: 41min 49sec (2509 seconds)
Published: Wed Sep 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.