1626890820
Bluehost Wordpress Install - How To Install WordPress On Bluehost 2020
Timestamps ð
00:00 Intro
00:16 Get Your Hosting Discount
00:34 Select Your Hosting Package
01:01 Pick Your Domain Name
02:03 Additional Discount
03:16 Log Into The Bluehost Dashboard
04:21 Go To âMy Sitesâ
04:31 Click âLog Into WordPressâ
05:07 Confirm Your Email Address
06:08 Go To My Sites and Click âManage Siteâ
06:24 Click âLaunch Your Siteâ
06:35 For The People Who Already Have Bluehost
Step 1 - Go to Your Bluehost Dashboard
Before this step, make sure youâre fully set-up with Bluehost and have a WordPress account. Considering youâre reading a guide on how to install WordPress on Bluehost, you most likely have already done that. Nonetheless, make sure you have a Bluehost plan selected and a WordPress account to begin with.
Once youâve done that, go to your Bluehost dashboard. At this point, you have everything needed, you just have to install WordPress on Bluehost. On your dashboard, you should see a variety of tabs such as home, sites, marketplace, email, domains, and advanced. At this point, donât worry about all of them for the time being. Just make sure youâre on the Bluehost dashboard.
Step 2 - Go to the Left Sidebar and Click on âmy sitesâ
Now that youâre on your Bluehost dashboard. Take a look at the left sidebar, and look for my sites. It should be the 2nd one from the top, and not too tricky to find. Once discovered, click on it. This tab is where youâll control all of your sites you have connected to Bluehost, and will use to add new sites.
Be familiar with this tab if you want to add more sites, remove a site, and so on. Plus, itâs where youâll go to connect WordPress on Bluehost. Bluehost has a straightforward set-up system, which makes them one of the best options to choose from. Nonetheless, click on my sites, and you can move on to step three.
Step 3 - Click on the Blue âcreate siteâ Button
Once youâre on the my sites tab, next, youâll click on create site. Unless you already have a website connected to Bluehost, you shouldnât see any websites down below. If you have a bunch of websites on there, you most likely wouldnât be using this guide anyway.
Nonetheless, click on create site, and youâll be ready for the next step. Keep this in mind for when you want to add future sites. No matter what the case might be, this is a simple tool for installing WordPress on Bluehost. Letâs move on.
Step 4 - When it Asks You, âHow would you like to build your website?â Click on the blue âuse WordPressâ button
Once you click on create site, itâll ask you how youâll like to build your website. Building your website comes in a variety of options, but make sure you hit the use WordPress button. That way, youâll be able to easily install WordPress on Bluehost.
Bluehost tries to make WordPressâs installation process remarkably simple and is why the entire method only takes a matter of a few buttons. Once you use the WordPress button, you only have a few more steps left in the whole process. Letâs continue forward!
Step 5 - Add a Title to Your Website and Click Next
Almost at the finish point, add a title to your website. Think of the title as what you want to represent your website. If youâre not sure of a title to utilize, donât worry too much about it. Take the needed time to think of one and move forward from there. Nonetheless, once you know of a title to your website, click next.
Now that you added the title to your website, it shouldnât be much longer from that point moving forward. At this point, the installation of WordPress is almost entirely complete. It just needs a final step to complete the process. Letâs look at the last step!
(Final step) Step 6 - Select your Website from the drop-down menu and click Next
Congratulations, youâre on the last step! At this point, go to the drop-down menu and select your website. Unless you have numerous websites connected to Bluehost, it should only pop-up with one site. Simple enough, right?
Once you see your website, click on it, and click next. Once the process completes, there shouldnât be any other future needs to properly install WordPress on Bluehost. You shouldnât have any issues related to this since Bluehost makes it such a straightforward process with installing process.
WordPress is Now Installed!
Note: To keep these video tutorials free, I make a small commission every time you purchase through the links in the description.
#Bluehost #BluehostWordPressInstall #BluehostWordPress
#wordpress
1657107416
The era of mobile app development has completely changed the scenario for businesses in regions like Abu Dhabi. Restaurants and food delivery businesses are experiencing huge benefits via smart business applications. The invention and development of the food ordering app have helped all-scale businesses reach new customers and boost sales and profit.
As a result, many business owners are searching for the best restaurant mobile app development company in Abu Dhabi. If you are also searching for the same, this article is helpful for you. It will let you know the step-by-step process to hire the right team of restaurant mobile app developers.
Searching for the top mobile app development company in Abu Dhabi? Don't know the best way to search for professionals? Don't panic! Here is the step-by-step process to hire the best professionals.
#Step 1 â Know the Company's Culture
Knowing the organization's culture is very crucial before finalizing a food ordering app development company in Abu Dhabi. An organization's personality is shaped by its common beliefs, goals, practices, or company culture. So, digging into the company culture reveals the core beliefs of the organization, its objectives, and its development team.
Now, you might be wondering, how will you identify the company's culture? Well, you can take reference from the following sources â
#Step 2 - Refer to Clients' Reviews
Another best way to choose the On-demand app development firm for your restaurant business is to refer to the clients' reviews. Reviews are frequently available on the organization's website with a tag of "Reviews" or "Testimonials." It's important to read the reviews as they will help you determine how happy customers are with the company's app development process.
You can also assess a company's abilities through reviews and customer testimonials. They can let you know if the mobile app developers create a valuable app or not.
#Step 3 â Analyze the App Development Process
Regardless of the company's size or scope, adhering to the restaurant delivery app development process will ensure the success of your business application. Knowing the processes an app developer follows in designing and producing a top-notch app will help you know the working process. Organizations follow different app development approaches, so getting well-versed in the process is essential before finalizing any mobile app development company.
#Step 4 â Consider Previous Experience
Besides considering other factors, considering the previous experience of the developers is a must. You can obtain a broad sense of the developer's capacity to assist you in creating a unique mobile application for a restaurant business.
You can also find out if the developers' have contributed to the creation of other successful applications or not. It will help you know the working capacity of a particular developer or organization. Prior experience is essential to evaluating their work. For instance, whether they haven't previously produced an app similar to yours or not.
#Step 5 â Check for Their Technical Support
As you expect a working and successful restaurant mobile app for your business, checking on this factor is a must. A well-established organization is nothing without a good technical support team. So, ensure whatever restaurant mobile app development company you choose they must be well-equipped with a team of dedicated developers, designers, and testers.
Strong tech support from your mobile app developers will help you identify new bugs and fix them bugs on time. All this will ensure the application's success.
#Step 6 â Analyze Design Standards
Besides focusing on an organization's development, testing, and technical support, you should check the design standards. An appealing design is crucial in attracting new users and keeping the existing ones stick to your services. So, spend some time analyzing the design standards of an organization. Now, you might be wondering, how will you do it? Simple! By looking at the organization's portfolio.
Whether hiring an iPhone app development company or any other, these steps apply to all. So, don't miss these steps.
#Step 7 â Know Their Location
Finally, the last yet very crucial factor that will not only help you finalize the right person for your restaurant mobile app development but will also decide the mobile app development cost. So, you have to choose the location of the developers wisely, as it is a crucial factor in defining the cost.
Summing Up!!!
Restaurant mobile applications have taken the food industry to heights none have ever considered. As a result, the demand for restaurant mobile app development companies has risen greatly, which is why businesses find it difficult to finalize the right person. But, we hope that after referring to this article, it will now be easier to hire dedicated developers under the desired budget. So, begin the hiring process now and get a well-craft food ordering app in hand.
1594753020
Multiple vulnerabilities in the Citrix Application Delivery Controller (ADC) and Gateway would allow code injection, information disclosure and denial of service, the networking vendor announced Tuesday. Four of the bugs are exploitable by an unauthenticated, remote attacker.
The Citrix products (formerly known as NetScaler ADC and Gateway) are used for application-aware traffic management and secure remote access, respectively, and are installed in at least 80,000 companies in 158 countries, according to a December assessment from Positive Technologies.
Other flaws announced Tuesday also affect Citrix SD-WAN WANOP appliances, models 4000-WO, 4100-WO, 5000-WO and 5100-WO.
Attacks on the management interface of the products could result in system compromise by an unauthenticated user on the management network; or system compromise through cross-site scripting (XSS). Attackers could also create a download link for the device which, if downloaded and then executed by an unauthenticated user on the management network, could result in the compromise of a local computer.
âCustomers who have configured their systems in accordance with Citrix recommendations [i.e., to have this interface separated from the network and protected by a firewall] have significantly reduced their risk from attacks to the management interface,â according to the vendor.
Threat actors could also mount attacks on Virtual IPs (VIPs). VIPs, among other things, are used to provide users with a unique IP address for communicating with network resources for applications that do not allow multiple connections or users from the same IP address.
The VIP attacks include denial of service against either the Gateway or Authentication virtual servers by an unauthenticated user; or remote port scanning of the internal network by an authenticated Citrix Gateway user.
âAttackers can only discern whether a TLS connection is possible with the port and cannot communicate further with the end devices,â according to the critical Citrix advisory. âCustomers who have not enabled either the Gateway or Authentication virtual servers are not at risk from attacks that are applicable to those servers. Other virtual servers e.g. load balancing and content switching virtual servers are not affected by these issues.â
A final vulnerability has been found in Citrix Gateway Plug-in for Linux that would allow a local logged-on user of a Linux system with that plug-in installed to elevate their privileges to an administrator account on that computer, the company said.
#vulnerabilities #adc #citrix #code injection #critical advisory #cve-2020-8187 #cve-2020-8190 #cve-2020-8191 #cve-2020-8193 #cve-2020-8194 #cve-2020-8195 #cve-2020-8196 #cve-2020-8197 #cve-2020-8198 #cve-2020-8199 #denial of service #gateway #information disclosure #patches #security advisory #security bugs
1561523460
This Matplotlib cheat sheet introduces you to the basics that you need to plot your data with Python and includes code samples.
Data visualization and storytelling with your data are essential skills that every data scientist needs to communicate insights gained from analyses effectively to any audience out there.
For most beginners, the first package that they use to get in touch with data visualization and storytelling is, naturally, Matplotlib: it is a Python 2D plotting library that enables users to make publication-quality figures. But, what might be even more convincing is the fact that other packages, such as Pandas, intend to build more plotting integration with Matplotlib as time goes on.
However, what might slow down beginners is the fact that this package is pretty extensive. There is so much that you can do with it and it might be hard to still keep a structure when you're learning how to work with Matplotlib.
DataCamp has created a Matplotlib cheat sheet for those who might already know how to use the package to their advantage to make beautiful plots in Python, but that still want to keep a one-page reference handy. Of course, for those who don't know how to work with Matplotlib, this might be the extra push be convinced and to finally get started with data visualization in Python.
You'll see that this cheat sheet presents you with the six basic steps that you can go through to make beautiful plots.
Check out the infographic by clicking on the button below:
With this handy reference, you'll familiarize yourself in no time with the basics of Matplotlib: you'll learn how you can prepare your data, create a new plot, use some basic plotting routines to your advantage, add customizations to your plots, and save, show and close the plots that you make.
What might have looked difficult before will definitely be more clear once you start using this cheat sheet! Use it in combination with the Matplotlib Gallery, the documentation.
Matplotlib
Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.
>>> import numpy as np
>>> x = np.linspace(0, 10, 100)
>>> y = np.cos(x)
>>> z = np.sin(x)
>>> data = 2 * np.random.random((10, 10))
>>> data2 = 3 * np.random.random((10, 10))
>>> Y, X = np.mgrid[-3:3:100j, -3:3:100j]
>>> U = 1 X** 2 + Y
>>> V = 1 + X Y**2
>>> from matplotlib.cbook import get_sample_data
>>> img = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> fig2 = plt.figure(figsize=plt.figaspect(2.0))
>>> fig.add_axes()
>>> ax1 = fig.add_subplot(221) #row-col-num
>>> ax3 = fig.add_subplot(212)
>>> fig3, axes = plt.subplots(nrows=2,ncols=2)
>>> fig4, axes2 = plt.subplots(ncols=3)
>>> plt.savefig('foo.png') #Save figures
>>> plt.savefig('foo.png', transparent=True) #Save transparent figures
>>> plt.show()
>>> fig, ax = plt.subplots()
>>> lines = ax.plot(x,y) #Draw points with lines or markers connecting them
>>> ax.scatter(x,y) #Draw unconnected points, scaled or colored
>>> axes[0,0].bar([1,2,3],[3,4,5]) #Plot vertical rectangles (constant width)
>>> axes[1,0].barh([0.5,1,2.5],[0,1,2]) #Plot horiontal rectangles (constant height)
>>> axes[1,1].axhline(0.45) #Draw a horizontal line across axes
>>> axes[0,1].axvline(0.65) #Draw a vertical line across axes
>>> ax.fill(x,y,color='blue') #Draw filled polygons
>>> ax.fill_between(x,y,color='yellow') #Fill between y values and 0
>>> fig, ax = plt.subplots()
>>> im = ax.imshow(img, #Colormapped or RGB arrays
cmap= 'gist_earth',
interpolation= 'nearest',
vmin=-2,
vmax=2)
>>> axes2[0].pcolor(data2) #Pseudocolor plot of 2D array
>>> axes2[0].pcolormesh(data) #Pseudocolor plot of 2D array
>>> CS = plt.contour(Y,X,U) #Plot contours
>>> axes2[2].contourf(data1) #Plot filled contours
>>> axes2[2]= ax.clabel(CS) #Label a contour plot
>>> axes[0,1].arrow(0,0,0.5,0.5) #Add an arrow to the axes
>>> axes[1,1].quiver(y,z) #Plot a 2D field of arrows
>>> axes[0,1].streamplot(X,Y,U,V) #Plot a 2D field of arrows
>>> ax1.hist(y) #Plot a histogram
>>> ax3.boxplot(y) #Make a box and whisker plot
>>> ax3.violinplot(z) #Make a violin plot
y-axis
x-axis
The basic steps to creating plots with matplotlib are:
1 Prepare Data
2 Create Plot
3 Plot
4 Customized Plot
5 Save Plot
6 Show Plot
>>> import matplotlib.pyplot as plt
>>> x = [1,2,3,4] #Step 1
>>> y = [10,20,25,30]
>>> fig = plt.figure() #Step 2
>>> ax = fig.add_subplot(111) #Step 3
>>> ax.plot(x, y, color= 'lightblue', linewidth=3) #Step 3, 4
>>> ax.scatter([2,4,6],
[5,15,25],
color= 'darkgreen',
marker= '^' )
>>> ax.set_xlim(1, 6.5)
>>> plt.savefig('foo.png' ) #Step 5
>>> plt.show() #Step 6
>>> plt.cla() #Clear an axis
>>> plt.clf(). #Clear the entire figure
>>> plt.close(). #Close a window
>>> plt.plot(x, x, x, x**2, x, x** 3)
>>> ax.plot(x, y, alpha = 0.4)
>>> ax.plot(x, y, c= 'k')
>>> fig.colorbar(im, orientation= 'horizontal')
>>> im = ax.imshow(img,
cmap= 'seismic' )
>>> fig, ax = plt.subplots()
>>> ax.scatter(x,y,marker= ".")
>>> ax.plot(x,y,marker= "o")
>>> plt.plot(x,y,linewidth=4.0)
>>> plt.plot(x,y,ls= 'solid')
>>> plt.plot(x,y,ls= '--')
>>> plt.plot(x,y,'--' ,x**2,y**2,'-.' )
>>> plt.setp(lines,color= 'r',linewidth=4.0)
>>> ax.text(1,
-2.1,
'Example Graph',
style= 'italic' )
>>> ax.annotate("Sine",
xy=(8, 0),
xycoords= 'data',
xytext=(10.5, 0),
textcoords= 'data',
arrowprops=dict(arrowstyle= "->",
connectionstyle="arc3"),)
>>> plt.title(r '$sigma_i=15$', fontsize=20)
Limits & Autoscaling
>>> ax.margins(x=0.0,y=0.1) #Add padding to a plot
>>> ax.axis('equal') #Set the aspect ratio of the plot to 1
>>> ax.set(xlim=[0,10.5],ylim=[-1.5,1.5]) #Set limits for x-and y-axis
>>> ax.set_xlim(0,10.5) #Set limits for x-axis
Legends
>>> ax.set(title= 'An Example Axes', #Set a title and x-and y-axis labels
ylabel= 'Y-Axis',
xlabel= 'X-Axis')
>>> ax.legend(loc= 'best') #No overlapping plot elements
Ticks
>>> ax.xaxis.set(ticks=range(1,5), #Manually set x-ticks
ticklabels=[3,100, 12,"foo" ])
>>> ax.tick_params(axis= 'y', #Make y-ticks longer and go in and out
direction= 'inout',
length=10)
Subplot Spacing
>>> fig3.subplots_adjust(wspace=0.5, #Adjust the spacing between subplots
hspace=0.3,
left=0.125,
right=0.9,
top=0.9,
bottom=0.1)
>>> fig.tight_layout() #Fit subplot(s) in to the figure area
Axis Spines
>>> ax1.spines[ 'top'].set_visible(False) #Make the top axis line for a plot invisible
>>> ax1.spines['bottom' ].set_position(( 'outward',10)) #Move the bottom axis line outward
Have this Cheat Sheet at your fingertips
Original article source at https://www.datacamp.com
#matplotlib #cheatsheet #python
1626890820
Bluehost Wordpress Install - How To Install WordPress On Bluehost 2020
Timestamps ð
00:00 Intro
00:16 Get Your Hosting Discount
00:34 Select Your Hosting Package
01:01 Pick Your Domain Name
02:03 Additional Discount
03:16 Log Into The Bluehost Dashboard
04:21 Go To âMy Sitesâ
04:31 Click âLog Into WordPressâ
05:07 Confirm Your Email Address
06:08 Go To My Sites and Click âManage Siteâ
06:24 Click âLaunch Your Siteâ
06:35 For The People Who Already Have Bluehost
Step 1 - Go to Your Bluehost Dashboard
Before this step, make sure youâre fully set-up with Bluehost and have a WordPress account. Considering youâre reading a guide on how to install WordPress on Bluehost, you most likely have already done that. Nonetheless, make sure you have a Bluehost plan selected and a WordPress account to begin with.
Once youâve done that, go to your Bluehost dashboard. At this point, you have everything needed, you just have to install WordPress on Bluehost. On your dashboard, you should see a variety of tabs such as home, sites, marketplace, email, domains, and advanced. At this point, donât worry about all of them for the time being. Just make sure youâre on the Bluehost dashboard.
Step 2 - Go to the Left Sidebar and Click on âmy sitesâ
Now that youâre on your Bluehost dashboard. Take a look at the left sidebar, and look for my sites. It should be the 2nd one from the top, and not too tricky to find. Once discovered, click on it. This tab is where youâll control all of your sites you have connected to Bluehost, and will use to add new sites.
Be familiar with this tab if you want to add more sites, remove a site, and so on. Plus, itâs where youâll go to connect WordPress on Bluehost. Bluehost has a straightforward set-up system, which makes them one of the best options to choose from. Nonetheless, click on my sites, and you can move on to step three.
Step 3 - Click on the Blue âcreate siteâ Button
Once youâre on the my sites tab, next, youâll click on create site. Unless you already have a website connected to Bluehost, you shouldnât see any websites down below. If you have a bunch of websites on there, you most likely wouldnât be using this guide anyway.
Nonetheless, click on create site, and youâll be ready for the next step. Keep this in mind for when you want to add future sites. No matter what the case might be, this is a simple tool for installing WordPress on Bluehost. Letâs move on.
Step 4 - When it Asks You, âHow would you like to build your website?â Click on the blue âuse WordPressâ button
Once you click on create site, itâll ask you how youâll like to build your website. Building your website comes in a variety of options, but make sure you hit the use WordPress button. That way, youâll be able to easily install WordPress on Bluehost.
Bluehost tries to make WordPressâs installation process remarkably simple and is why the entire method only takes a matter of a few buttons. Once you use the WordPress button, you only have a few more steps left in the whole process. Letâs continue forward!
Step 5 - Add a Title to Your Website and Click Next
Almost at the finish point, add a title to your website. Think of the title as what you want to represent your website. If youâre not sure of a title to utilize, donât worry too much about it. Take the needed time to think of one and move forward from there. Nonetheless, once you know of a title to your website, click next.
Now that you added the title to your website, it shouldnât be much longer from that point moving forward. At this point, the installation of WordPress is almost entirely complete. It just needs a final step to complete the process. Letâs look at the last step!
(Final step) Step 6 - Select your Website from the drop-down menu and click Next
Congratulations, youâre on the last step! At this point, go to the drop-down menu and select your website. Unless you have numerous websites connected to Bluehost, it should only pop-up with one site. Simple enough, right?
Once you see your website, click on it, and click next. Once the process completes, there shouldnât be any other future needs to properly install WordPress on Bluehost. You shouldnât have any issues related to this since Bluehost makes it such a straightforward process with installing process.
WordPress is Now Installed!
Note: To keep these video tutorials free, I make a small commission every time you purchase through the links in the description.
#Bluehost #BluehostWordPressInstall #BluehostWordPress
#wordpress
1635917640
ãã®ã¢ãžã¥ãŒã«ã§ã¯ãRustã§ããã·ã¥ãããè€åããŒã¿åãæäœããæ¹æ³ã«ã€ããŠèª¬æããŸããããã·ã¥ãããã®ãããªã³ã¬ã¯ã·ã§ã³å ã®ããŒã¿ãå埩åŠçããã«ãŒãåŒãå®è£ ããæ¹æ³ãåŠã³ãŸããæŒç¿ãšããŠãèŠæ±ãããæ³šæãã«ãŒãããæ¡ä»¶ããã¹ãããããŸããŸãªã¿ã€ãã®ããŒã¿ãåŠçããããšã«ãã£ãŠè»ãäœæããRustããã°ã©ã ãäœæããŸãã
ééã³å Žã¯éã³ã³ãã€ã©ã«ãã©ãŠã¶ã€ã³ã¿ãã§ãŒã¹ã§ããèšèªãããŒã«ã«ã«ã€ã³ã¹ããŒã«ããåããŸãã¯ã³ã³ãã€ã©ãå©çšã§ããªãå Žåã¯ãPlaygroundã䜿çšããŠRustã³ãŒãã®èšè¿°ã詊ãããšãã§ããŸãããã®ã³ãŒã¹å šäœãéããŠããµã³ãã«ã³ãŒããšæŒç¿ãžã®Playgroundãªã³ã¯ãæäŸããŸããçŸæç¹ã§RustããŒã«ãã§ãŒã³ã䜿çšã§ããªãå Žåã§ããã³ãŒããæäœã§ããŸãã
Rust Playgroundã§å®è¡ããããã¹ãŠã®ã³ãŒãã¯ãããŒã«ã«ã®éçºç°å¢ã§ã³ã³ãã€ã«ããŠå®è¡ããããšãã§ããŸããã³ã³ãã¥ãŒã¿ãŒããRustã³ã³ãã€ã©ãŒãšå¯Ÿè©±ããããšãèºèºããªãã§ãã ãããRust Playgroundã®è©³çްã«ã€ããŠã¯ãWhat isRustïŒãã芧ãã ãããã¢ãžã¥ãŒã«ã
ãã®ã¢ãžã¥ãŒã«ã§ã¯ã次ã®ããšãè¡ããŸãã
Rustã®ãã1ã€ã®äžè¬çãªã³ã¬ã¯ã·ã§ã³ã®çš®é¡ã¯ãããã·ã¥ãããã§ãããã®HashMap<K, V>
åã¯ãåããŒK
ããã®å€ã«ãããã³ã°ããããšã«ãã£ãŠããŒã¿ãæ ŒçŽããŸãV
ããã¯ãã«å
ã®ããŒã¿ã¯æŽæ°ã€ã³ããã¯ã¹ã䜿çšããŠã¢ã¯ã»ã¹ãããŸãããããã·ã¥ãããå
ã®ããŒã¿ã¯ããŒã䜿çšããŠã¢ã¯ã»ã¹ãããŸãã
ããã·ã¥ãããã¿ã€ãã¯ããªããžã§ã¯ããããã·ã¥ããŒãã«ãèŸæžãªã©ã®ããŒã¿é ç®ã®å€ãã®ããã°ã©ãã³ã°èšèªã§äœ¿çšãããŸãã
ãã¯ãã«ã®ããã«ãããã·ã¥ãããã¯æ¡åŒµå¯èœã§ããããŒã¿ã¯ããŒãã«æ ŒçŽãããããã·ã¥ãããã¢ã€ãã ãžã®ã¢ã¯ã»ã¹ã¯å®è¡æã«ãã§ãã¯ãããŸãã
次ã®äŸã§ã¯ãæžè©ã远跡ããããã®ããã·ã¥ããããå®çŸ©ããŠããŸããããã·ã¥ãããããŒã¯æ¬ã®ååã§ãããå€ã¯èªè ã®ã¬ãã¥ãŒã§ãã
use std::collections::HashMap;
let mut reviews: HashMap<String, String> = HashMap::new();
reviews.insert(String::from("Ancient Roman History"), String::from("Very accurate."));
reviews.insert(String::from("Cooking with Rhubarb"), String::from("Sweet recipes."));
reviews.insert(String::from("Programming in Rust"), String::from("Great examples."));
ãã®ã³ãŒããããã«è©³ãã調ã¹ãŠã¿ãŸããããæåã®è¡ã«ãæ°ããã¿ã€ãã®æ§æã衚瀺ãããŸãã
use std::collections::HashMap;
ãã®use
ã³ãã³ãã¯ãRustæšæºã©ã€ãã©ãªã®äžéšHashMap
ããã®å®çŸ©ãcollections
ããã°ã©ã ã®ã¹ã³ãŒãã«åã蟌ã¿ãŸãããã®æ§æã¯ãä»ã®ããã°ã©ãã³ã°èšèªãã€ã³ããŒããšåŒã¶ãã®ãšäŒŒãŠããŸãã
HashMap::new
ã¡ãœããã䜿çšããŠç©ºã®ããã·ã¥ããããäœæããŸããreviews
å¿
èŠã«å¿ããŠããŒãšå€ã远å ãŸãã¯åé€ã§ããããã«ã倿°ãå¯å€ãšããŠå®£èšããŸãããã®äŸã§ã¯ãããã·ã¥ãããã®ããŒãšå€ã®äž¡æ¹ãString
ã¿ã€ãã䜿çšããŠããŸãã
let mut reviews: HashMap<String, String> = HashMap::new();
ãã®insert(<key>, <value>)
ã¡ãœããã䜿çšããŠãããã·ã¥ãããã«èŠçŽ ã远å ããŸããã³ãŒãã§ã¯ãæ§æã¯<hash_map_name>.insert()
次ã®ãšããã§ãã
reviews.insert(String::from("Ancient Roman History"), String::from("Very accurate."));
ããã·ã¥ãããã«ããŒã¿ã远å ããåŸãget(<key>)
ã¡ãœããã䜿çšããŠããŒã®ç¹å®ã®å€ãååŸã§ããŸãã
// Look for a specific review
let book: &str = "Programming in Rust";
println!("\nReview for \'{}\': {:?}", book, reviews.get(book));
åºåã¯æ¬¡ã®ãšããã§ãã
Review for 'Programming in Rust': Some("Great examples.")
ããŒã
åºåã«ã¯ãæžè©ãåãªãããã°ãããäŸãã§ã¯ãªããSomeïŒ "ãã°ãããäŸã"ïŒããšããŠè¡šç€ºãããŠããããšã«æ³šæããŠãã ãããget
ã¡ãœããã¯Option<&Value>
åãè¿ããããRustã¯ã¡ãœããåŒã³åºãã®çµæããSomeïŒïŒã衚èšã§ã©ããããŸãã
ãã®.remove()
ã¡ãœããã䜿çšããŠãããã·ã¥ããããããšã³ããªãåé€ã§ããŸããget
ç¡å¹ãªããã·ã¥ãããããŒã«å¯ŸããŠã¡ãœããã䜿çšãããšãget
ã¡ãœããã¯ããªãããè¿ããŸãã
// Remove book review
let obsolete: &str = "Ancient Roman History";
println!("\n'{}\' removed.", obsolete);
reviews.remove(obsolete);
// Confirm book review removed
println!("\nReview for \'{}\': {:?}", obsolete, reviews.get(obsolete));
åºåã¯æ¬¡ã®ãšããã§ãã
'Ancient Roman History' removed.
Review for 'Ancient Roman History': None
ãã®ã³ãŒãã詊ããŠããã®RustPlaygroundã§ããã·ã¥ããããæäœã§ããŸãã
æŒç¿ïŒããã·ã¥ãããã䜿çšããŠæ³šæã远跡ãã
ãã®æŒç¿ã§ã¯ãããã·ã¥ãããã䜿çšããããã«èªåè»å·¥å Žã®ããã°ã©ã ã倿ŽããŸãã
ããã·ã¥ãããããŒãšå€ã®ãã¢ã䜿çšããŠãè»ã®æ³šæã«é¢ãã詳现ã远跡ããåºåã衚瀺ããŸããç¹°ãè¿ãã«ãªããŸãããããªãã®èª²é¡ã¯ããµã³ãã«ã³ãŒãã宿ãããŠã³ã³ãã€ã«ããŠå®è¡ããããšã§ãã
ãã®æŒç¿ã®ãµã³ãã«ã³ãŒãã§äœæ¥ããã«ã¯ã次ã®2ã€ã®ãªãã·ã§ã³ããããŸãã
ããŒã
ãµã³ãã«ã³ãŒãã§ã
todo!
ãã¯ããæ¢ããŸãããã®ãã¯ãã¯ãå®äºãããæŽæ°ããå¿ èŠãããã³ãŒãã瀺ããŸãã
æåã®ã¹ãããã¯ãæ¢åã®ããã°ã©ã ã³ãŒããååŸããããšã§ãã
car_quality
ãcar_factory
ããã³main
æ©èœããæ¬¡ã®ã³ãŒããã³ããŒããŠããŒã«ã«éçºç°å¢ã§ç·šéãã
ãããã®æºåãããRustPlaygroundã§ã³ãŒããéããŸãã
#[derive(PartialEq, Debug)]
struct Car { color: String, motor: Transmission, roof: bool, age: (Age, u32) }
#[derive(PartialEq, Debug)]
enum Transmission { Manual, SemiAuto, Automatic }
#[derive(PartialEq, Debug)]
enum Age { New, Used }
// Get the car quality by testing the value of the input argument
// - miles (u32)
// Return tuple with car age ("New" or "Used") and mileage
fn car_quality (miles: u32) -> (Age, u32) {
// Check if car has accumulated miles
// Return tuple early for Used car
if miles > 0 {
return (Age::Used, miles);
}
// Return tuple for New car, no need for "return" keyword or semicolon
(Age::New, miles)
}
// Build "Car" using input arguments
fn car_factory(order: i32, miles: u32) -> Car {
let colors = ["Blue", "Green", "Red", "Silver"];
// Prevent panic: Check color index for colors array, reset as needed
// Valid color = 1, 2, 3, or 4
// If color > 4, reduce color to valid index
let mut color = order as usize;
if color > 4 {
// color = 5 --> index 1, 6 --> 2, 7 --> 3, 8 --> 4
color = color - 4;
}
// Add variety to orders for motor type and roof type
let mut motor = Transmission::Manual;
let mut roof = true;
if order % 3 == 0 { // 3, 6, 9
motor = Transmission::Automatic;
} else if order % 2 == 0 { // 2, 4, 8, 10
motor = Transmission::SemiAuto;
roof = false;
} // 1, 5, 7, 11
// Return requested "Car"
Car {
color: String::from(colors[(color-1) as usize]),
motor: motor,
roof: roof,
age: car_quality(miles)
}
}
fn main() {
// Initialize counter variable
let mut order = 1;
// Declare a car as mutable "Car" struct
let mut car: Car;
// Order 6 cars, increment "order" for each request
// Car order #1: Used, Hard top
car = car_factory(order, 1000);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
// Car order #2: Used, Convertible
order = order + 1;
car = car_factory(order, 2000);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
// Car order #3: New, Hard top
order = order + 1;
car = car_factory(order, 0);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
// Car order #4: New, Convertible
order = order + 1;
car = car_factory(order, 0);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
// Car order #5: Used, Hard top
order = order + 1;
car = car_factory(order, 3000);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
// Car order #6: Used, Hard top
order = order + 1;
car = car_factory(order, 4000);
println!("{}: {:?}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
}
2. ããã°ã©ã ããã«ãããŸããæ¬¡ã®ã»ã¯ã·ã§ã³ã«é²ãåã«ãã³ãŒããã³ã³ãã€ã«ãããŠå®è¡ãããããšã確èªããŠãã ããã
次ã®åºåã衚瀺ãããŸãã
1: Used, Hard top = true, Manual, Blue, 1000 miles
2: Used, Hard top = false, SemiAuto, Green, 2000 miles
3: New, Hard top = true, Automatic, Red, 0 miles
4: New, Hard top = false, SemiAuto, Silver, 0 miles
5: Used, Hard top = true, Manual, Blue, 3000 miles
6: Used, Hard top = true, Automatic, Green, 4000 miles
çŸåšã®ããã°ã©ã ã¯ãåè»ã®æ³šæãåŠçããåæ³šæãå®äºããåŸã«èŠçŽãå°å·ããŸããcar_factory
颿°ãåŒã³åºããã³ã«Car
ãæ³šæã®è©³çްãå«ãæ§é äœãè¿ãããæ³šæãå®è¡ãããŸããçµæã¯car
倿°ã«æ ŒçŽãããŸãã
ãæ°ã¥ããããããŸãããããã®ããã°ã©ã ã«ã¯ããã€ãã®éèŠãªæ©èœããããŸããããã¹ãŠã®æ³šæã远跡ããŠããããã§ã¯ãããŸãããcar
倿°ã¯ãçŸåšã®æ³šæã®è©³çްã®ã¿ãä¿æããŠããŸãã颿°car
ã®çµæã§å€æ°ãæŽæ°ããããã³car_factory
ã«ãåã®é åºã®è©³çްãäžæžããããŸãã
ãã¡ã€ãªã³ã°ã·ã¹ãã ã®ããã«ãã¹ãŠã®æ³šæã远跡ããããã«ãããã°ã©ã ãæŽæ°ããå¿
èŠããããŸãããã®ç®çã®ããã«ã<KãV>ãã¢ã§ããã·ã¥ããããå®çŸ©ããŸããããã·ã¥ãããããŒã¯ãè»ã®æ³šæçªå·ã«å¯Ÿå¿ããŸããããã·ã¥ãããå€ã¯ãCar
æ§é äœã§å®çŸ©ãããŠããããããã®æ³šæã®è©³çްã«ãªããŸãã
main
颿°ã®å
é ãæåã®äžæ¬åŒ§ã®çŽåŸã«æ¬¡ã®ã³ãŒãã远å ããŸã{
ã// Initialize a hash map for the car orders
// - Key: Car order number, i32
// - Value: Car order details, Car struct
use std::collections::HashMap;
let mut orders: HashMap<i32, Car> = HashMap;
2. orders
ããã·ã¥ããããäœæããã¹ããŒãã¡ã³ãã®æ§æã®åé¡ãä¿®æ£ããŸãã
ãã³ã
ããã·ã¥ããããæåããäœæããŠããã®ã§ããããããã®
new()
ã¡ãœããã䜿çšããããšããå§ãããŸãã
3. ããã°ã©ã ããã«ãããŸããæ¬¡ã®ã»ã¯ã·ã§ã³ã«é²ãåã«ãã³ãŒããã³ã³ãã€ã«ãããŠããããšã確èªããŠãã ãããã³ã³ãã€ã©ããã®èŠåã¡ãã»ãŒãžã¯ç¡èŠããŠããŸããŸããã
次ã®ã¹ãããã¯ãå±¥è¡ãããåèªåè»æ³šæãããã·ã¥ãããã«è¿œå ããããšã§ãã
ãã®main
颿°ã§ã¯ãcar_factory
è»ã®æ³šæããšã«é¢æ°ãåŒã³åºããŸããæ³šæãå±¥è¡ãããåŸãprintln!
ãã¯ããåŒã³åºããŠãcar
倿°ã«æ ŒçŽãããŠããæ³šæã®è©³çްã衚瀺ããŸãã
// Car order #1: Used, Hard top
car = car_factory(order, 1000);
println!("{}: {}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
...
// Car order #6: Used, Hard top
order = order + 1;
car = car_factory(order, 4000);
println!("{}: {}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
æ°ããããã·ã¥ãããã§æ©èœããããã«ããããã®ã³ãŒãã¹ããŒãã¡ã³ããä¿®æ£ããŸãã
car_factory
颿°ã®åŒã³åºãã¯ä¿æããŸããè¿ãããåCar
æ§é äœã¯ãããã·ã¥ãããã®<KãV>ãã¢ã®äžéšãšããŠæ ŒçŽãããŸããprintln!
ãã¯ãã®åŒã³åºããæŽæ°ããŠãããã·ã¥ãããã«ä¿åãããŠããæ³šæã®è©³çްã衚瀺ããŸããmain
颿°ã§ã颿°ã®åŒã³åºãcar_factory
ãšããã«äŒŽãprintln!
ãã¯ãã®åŒã³åºããèŠã€ããŸãã// Car order #1: Used, Hard top
car = car_factory(order, 1000);
println!("{}: {}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
...
// Car order #6: Used, Hard top
order = order + 1;
car = car_factory(order, 4000);
println!("{}: {}, Hard top = {}, {:?}, {}, {} miles", order, car.age.0, car.roof, car.motor, car.color, car.age.1);
2. ãã¹ãŠã®èªåè»æ³šæã®ã¹ããŒãã¡ã³ãã®å®å šãªã»ãããæ¬¡ã®æ¹èšãããã³ãŒãã«çœ®ãæããŸãã
// Car order #1: Used, Hard top
car = car_factory(order, 1000);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Car order #2: Used, Convertible
order = order + 1;
car = car_factory(order, 2000);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Car order #3: New, Hard top
order = order + 1;
car = car_factory(order, 0);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Car order #4: New, Convertible
order = order + 1;
car = car_factory(order, 0);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Car order #5: Used, Hard top
order = order + 1;
car = car_factory(order, 3000);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Car order #6: Used, Hard top
order = order + 1;
car = car_factory(order, 4000);
orders(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
3. ä»ããããã°ã©ã ããã«ãããããšãããšãã³ã³ãã€ã«ãšã©ãŒã衚瀺ãããŸãã<KãV>ãã¢ãorders
ããã·ã¥ãããã«è¿œå ããã¹ããŒãã¡ã³ãã«æ§æäžã®åé¡ããããŸããåé¡ããããŸããïŒå
ã«é²ãã§ãããã·ã¥ãããã«é åºã远å ããåã¹ããŒãã¡ã³ãã®åé¡ãä¿®æ£ããŠãã ããã
ãã³ã
orders
ããã·ã¥ãããã«çŽæ¥å€ãå²ãåœãŠãããšã¯ã§ããŸãããæ¿å ¥ãè¡ãã«ã¯ã¡ãœããã䜿çšããå¿ èŠããããŸãã
ããã°ã©ã ãæ£åžžã«ãã«ãããããšã次ã®åºåã衚瀺ãããŸãã
Car order 1: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("Used", 1000) })
Car order 2: Some(Car { color: "Green", motor: SemiAuto, roof: false, age: ("Used", 2000) })
Car order 3: Some(Car { color: "Red", motor: Automatic, roof: true, age: ("New", 0) })
Car order 4: Some(Car { color: "Silver", motor: SemiAuto, roof: false, age: ("New", 0) })
Car order 5: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("Used", 3000) })
Car order 6: Some(Car { color: "Green", motor: Automatic, roof: true, age: ("Used", 4000) })
æ¹èšãããã³ãŒãã®åºåãç°ãªãããšã«æ³šæããŠãã ãããprintln!
ãã¯ããã£ã¹ãã¬ã€ã®å
容Car
åå€ã瀺ãããšã«ãã£ãŠãæ§é äœãšå¯Ÿå¿ãããã£ãŒã«ãåã
æ¬¡ã®æŒç¿ã§ã¯ãã«ãŒãåŒã䜿çšããŠã³ãŒãã®åé·æ§ãæžãããŸãã
forãwhileãããã³loopåŒã䜿çšããŸã
å€ãã®å Žåãããã°ã©ã ã«ã¯ããã®å Žã§ç¹°ãè¿ãå¿
èŠã®ããã³ãŒãã®ãããã¯ããããŸããã«ãŒãåŒã䜿çšããŠãç¹°ãè¿ãã®å®è¡æ¹æ³ãããã°ã©ã ã«æç€ºã§ããŸããé»è©±åž³ã®ãã¹ãŠã®ãšã³ããªãå°å·ããã«ã¯ãã«ãŒãåŒã䜿çšããŠãæåã®ãšã³ããªããæåŸã®ãšã³ããªãŸã§å°å·ããæ¹æ³ãããã°ã©ã ã«æç€ºã§ããŸãã
Rustã¯ãããã°ã©ã ã«ã³ãŒãã®ãããã¯ãç¹°ãè¿ãããããã®3ã€ã®ã«ãŒãåŒãæäŸããŸãã
loop
ïŒæå忢ãçºçããªãéããç¹°ãè¿ããŸããwhile
ïŒæ¡ä»¶ãçã®ãŸãŸã§ç¹°ãè¿ããŸããfor
ïŒã³ã¬ã¯ã·ã§ã³å
ã®ãã¹ãŠã®å€ã«å¯ŸããŠç¹°ãè¿ããŸãããã®åå ã§ã¯ããããã®åã«ãŒãåŒãèŠãŠãããŸãã
loop
åŒã¯ãç¡éã«ãŒããäœæããŸãããã®ããŒã¯ãŒãã䜿çšãããšãåŒã®æ¬æã§ã¢ã¯ã·ã§ã³ãç¶ç¶çã«ç¹°ãè¿ãããšãã§ããŸããã«ãŒãã忢ãããããã®çŽæ¥ã¢ã¯ã·ã§ã³ãå®è¡ãããŸã§ãã¢ã¯ã·ã§ã³ãç¹°ãè¿ãããŸãã
次ã®äŸã§ã¯ããWe loopforeverïŒããšããããã¹ããåºåããŸãããããŠããã¯ããèªäœã§æ¢ãŸããŸãããprintln!
ã¢ã¯ã·ã§ã³ã¯ç¹°ãè¿ãç¶ããŸãã
loop {
println!("We loop forever!");
}
loop
åŒã䜿çšããå Žåãã«ãŒãã忢ããå¯äžã®æ¹æ³ã¯ãããã°ã©ããŒãšããŠçŽæ¥ä»å
¥ããå Žåã§ããç¹å®ã®ã³ãŒãã远å ããŠã«ãŒãã忢ããããCtrl + Cãªã©ã®ããŒããŒãåœä»€ãå
¥åããŠããã°ã©ã ã®å®è¡ã忢ãããã§ããŸãã
loop
åŒã忢ããæãäžè¬çãªæ¹æ³ã¯ãbreak
ããŒã¯ãŒãã䜿çšããŠãã¬ãŒã¯ãã€ã³ããèšå®ããããšã§ãã
loop {
// Keep printing, printing, printing...
println!("We loop forever!");
// On the other hand, maybe we should stop!
break;
}
ããã°ã©ã ãbreak
ããŒã¯ãŒããæ€åºãããšãloop
åŒã®æ¬äœã§ã¢ã¯ã·ã§ã³ã®å®è¡ã忢ããæ¬¡ã®ã³ãŒãã¹ããŒãã¡ã³ãã«é²ã¿ãŸãã
break
ããŒã¯ãŒãã¯ãç¹å¥ãªæ©èœãæããã«ããloop
衚çŸããbreak
ããŒã¯ãŒãã䜿çšãããšãåŒæ¬äœã§ã®ã¢ã¯ã·ã§ã³ã®ç¹°ãè¿ãã忢ããããšãããã¬ãŒã¯ãã€ã³ãã§å€ãè¿ãããšãã§ããŸãã
次ã®äŸã¯break
ãloop
åŒã§ããŒã¯ãŒãã䜿çšããŠå€ãè¿ãæ¹æ³ã瀺ããŠããŸãã
let mut counter = 1;
// stop_loop is set when loop stops
let stop_loop = loop {
counter *= 2;
if counter > 100 {
// Stop loop, return counter value
break counter;
}
};
// Loop should break when counter = 128
println!("Break the loop at counter = {}.", stop_loop);
åºåã¯æ¬¡ã®ãšããã§ãã
Break the loop at counter = 128.
ç§ãã¡ã®loop
衚çŸã®æ¬äœã¯ããããã®é£ç¶ããã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
stop_loop
倿°ã宣èšããŸããloop
åŒã®çµæã«ãã€ã³ãããããã«ããã°ã©ã ã«æç€ºããŸããloop
åŒã®æ¬äœã§ã¢ã¯ã·ã§ã³ãå®è¡ããŸãïŒcounter
å€ãçŸåšã®å€ã®2åã«ã€ã³ã¯ãªã¡ã³ãããŸããcounter
å€ã確èªããŠãã ãããcounter
å€ã100以äžã§ããã«ãŒãããæãåºãã
counter
å€ãè¿ããŸãã
4. ããcounter
å€ã100以äžã§ã¯ãããŸããã
ã«ãŒãæ¬äœã§ã¢ã¯ã·ã§ã³ãç¹°ãè¿ããŸãã
5. stop_loop
å€ãåŒã®counter
çµæã§ããå€ã«èšå®ããŸãloop
ã
loop
åŒæ¬äœã¯ãè€æ°ã®ãã¬ãŒã¯ãã€ã³ããæã€ããšãã§ããŸããåŒã«è€æ°ã®ãã¬ãŒã¯ãã€ã³ããããå Žåããã¹ãŠã®ãã¬ãŒã¯ãã€ã³ãã¯åãã¿ã€ãã®å€ãè¿ãå¿
èŠããããŸãããã¹ãŠã®å€ã¯ãæŽæ°åãæåååãããŒã«åãªã©ã§ããå¿
èŠããããŸãããã¬ãŒã¯ãã€ã³ããæç€ºçã«å€ãè¿ããªãå Žåãããã°ã©ã ã¯åŒã®çµæã空ã®ã¿ãã«ãšããŠè§£éããŸã()
ã
while
ã«ãŒãã¯ãæ¡ä»¶åŒã䜿çšããŠããŸããæ¡ä»¶åŒãçã§ããéããã«ãŒããç¹°ãè¿ãããŸãããã®ããŒã¯ãŒãã䜿çšãããšãæ¡ä»¶åŒãfalseã«ãªããŸã§ãåŒæ¬äœã®ã¢ã¯ã·ã§ã³ãå®è¡ã§ããŸãã
while
ã«ãŒãã¯ãããŒã«æ¡ä»¶åŒãè©äŸ¡ããããšããå§ãŸããŸããæ¡ä»¶åŒããšè©äŸ¡ãããtrue
ãšãæ¬äœã®ã¢ã¯ã·ã§ã³ãå®è¡ãããŸããã¢ã¯ã·ã§ã³ãå®äºãããšãå¶åŸ¡ã¯æ¡ä»¶åŒã«æ»ããŸããæ¡ä»¶åŒããšè©äŸ¡ãããfalse
ãšãwhile
åŒã¯åæ¢ããŸãã
次ã®äŸã§ã¯ãããã°ããã«ãŒãããŸã...ããšããããã¹ããåºåããŸããã«ãŒããç¹°ãè¿ããã³ã«ããã«ãŠã³ãã5æªæºã§ããããšããæ¡ä»¶ããã¹ããããŸããæ¡ä»¶ãçã®ãŸãŸã§ããéãåŒæ¬äœã®ã¢ã¯ã·ã§ã³ãå®è¡ãããŸããæ¡ä»¶ãçã§ãªããªã£ãåŸãwhile
ã«ãŒãã¯åæ¢ããããã°ã©ã ã¯æ¬¡ã®ã³ãŒãã¹ããŒãã¡ã³ãã«é²ã¿ãŸãã
while counter < 5 {
println!("We loop a while...");
counter = counter + 1;
}
for
ã«ãŒãã¯ãé
ç®ã®ã³ã¬ã¯ã·ã§ã³ãåŠçããããã«ã€ãã¬ãŒã¿ã䜿çšããŠããŸããã«ãŒãã¯ãã³ã¬ã¯ã·ã§ã³å
ã®åã¢ã€ãã ã®åŒæ¬äœã®ã¢ã¯ã·ã§ã³ãç¹°ãè¿ããŸãããã®ã¿ã€ãã®ã«ãŒãã®ç¹°ãè¿ãã¯ãå埩ãšåŒã°ããŸãããã¹ãŠã®å埩ãå®äºãããšãã«ãŒãã¯åæ¢ããŸãã
Rustã§ã¯ãé åããã¯ãã«ãããã·ã¥ããããªã©ãä»»æã®ã³ã¬ã¯ã·ã§ã³ã¿ã€ããå埩åŠçã§ããŸããRustã¯ã€ãã¬ãŒã¿ã䜿çšããŠãã³ã¬ã¯ã·ã§ã³å ã®åã¢ã€ãã ãæåããæåŸãŸã§ç§»åããŸãã
for
ã«ãŒãã¯ã€ãã¬ãŒã¿ãšããŠäžæå€æ°ã䜿çšããŠããŸãã倿°ã¯ã«ãŒãåŒã®éå§æã«æé»çã«å®£èšãããçŸåšã®å€ã¯å埩ããšã«èšå®ãããŸãã
次ã®ã³ãŒãã§ã¯ãã³ã¬ã¯ã·ã§ã³ã¯big_birds
é
åã§ãããã€ãã¬ãŒã¿ãŒã®ååã¯bird
ã§ãã
let big_birds = ["ostrich", "peacock", "stork"];
for bird in big_birds
iter()
ã¡ãœããã䜿çšããŠãã³ã¬ã¯ã·ã§ã³å
ã®ã¢ã€ãã ã«ã¢ã¯ã»ã¹ããŸããfor
åŒã¯çµæã«ã€ãã¬ãŒã¿ã®çŸåšã®å€ããã€ã³ãããiter()
æ¹æ³ãåŒæ¬äœã§ã¯ãã€ãã¬ãŒã¿å€ãæäœã§ããŸãã
let big_birds = ["ostrich", "peacock", "stork"];
for bird in big_birds.iter() {
println!("The {} is a big bird.", bird);
}
åºåã¯æ¬¡ã®ãšããã§ãã
The ostrich is a big bird.
The peacock is a big bird.
The stork is a big bird.
ã€ãã¬ãŒã¿ãäœæãããã1ã€ã®ç°¡åãªæ¹æ³ã¯ãç¯å²è¡šèšã䜿çšããããšã§ãa..b
ãã€ãã¬ãŒã¿ã¯a
å€ããå§ãŸãb
ã1ã¹ããããã€ç¶ããŸãããå€ã䜿çšããŸããb
ã
for number in 0..5 {
println!("{}", number * 2);
}
ãã®ã³ãŒãã¯ã0ã1ã2ã3ãããã³4ã®æ°å€ãnumber
ç¹°ãè¿ãåŠçããŸããã«ãŒãã®ç¹°ãè¿ãããšã«ãå€ã倿°ã«ãã€ã³ãããŸãã
åºåã¯æ¬¡ã®ãšããã§ãã
0
2
4
6
8
ãã®ã³ãŒããå®è¡ããŠããã®RustPlaygroundã§ã«ãŒããæ¢çŽ¢ã§ããŸãã
æŒç¿ïŒã«ãŒãã䜿çšããŠããŒã¿ãå埩åŠçãã
ãã®æŒç¿ã§ã¯ãèªåè»å·¥å Žã®ããã°ã©ã ã倿ŽããŠãã«ãŒãã䜿çšããŠèªåè»ã®æ³šæãå埩åŠçããŸãã
main
颿°ãæŽæ°ããŠã泚æã®å®å
šãªã»ãããåŠçããããã®ã«ãŒãåŒã远å ããŸããã«ãŒãæ§é ã¯ãã³ãŒãã®åé·æ§ãæžããã®ã«åœ¹ç«ã¡ãŸããã³ãŒããç°¡çŽ åããããšã§ã泚æéãç°¡åã«å¢ããããšãã§ããŸãã
ãã®car_factory
颿°ã§ã¯ãç¯å²å€ã®å€ã§ã®å®è¡æã®ãããã¯ãåé¿ããããã«ãå¥ã®ã«ãŒãã远å ããŸãã
課é¡ã¯ããµã³ãã«ã³ãŒãã宿ãããŠãã³ã³ãã€ã«ããŠå®è¡ããããšã§ãã
ãã®æŒç¿ã®ãµã³ãã«ã³ãŒãã§äœæ¥ããã«ã¯ã次ã®2ã€ã®ãªãã·ã§ã³ããããŸãã
ããŒã
ãµã³ãã«ã³ãŒãã§ã
todo!
ãã¯ããæ¢ããŸãããã®ãã¯ãã¯ãå®äºãããæŽæ°ããå¿ èŠãããã³ãŒãã瀺ããŸãã
ååã®æŒç¿ã§ããã°ã©ã ã³ãŒããéããå Žåã¯ããã®æºåãããRustPlaygroundã§ã³ãŒããå床éãããšãã§ããŸãã
å¿ ãããã°ã©ã ãåæ§ç¯ããã³ã³ãã€ã©ãšã©ãŒãªãã§å®è¡ãããããšã確èªããŠãã ããã
ããå€ãã®æ³šæããµããŒãããã«ã¯ãããã°ã©ã ãæŽæ°ããå¿ èŠããããŸããçŸåšã®ã³ãŒãæ§é ã§ã¯ãåé·ã¹ããŒãã¡ã³ãã䜿çšããŠ6ã€ã®æ³šæããµããŒãããŠããŸããåé·æ§ã¯æ±ãã«ãããç¶æããã®ãå°é£ã§ãã
ã«ãŒãåŒã䜿çšããŠã¢ã¯ã·ã§ã³ãç¹°ãè¿ããåæ³šæãäœæããããšã§ãæ§é ãåçŽåã§ããŸããç°¡ç¥åãããã³ãŒãã䜿çšãããšã倿°ã®æ³šæããã°ããäœæã§ããŸãã
main
æ©èœãå逿¬¡ã®æãããã®ã³ãŒããããã¯ã¯ãorder
倿°ãå®çŸ©ããã³èšå®ããèªåè»ã®æ³šæã®car_factory
颿°ãšprintln!
ãã¯ããåŒã³åºããåæ³šæãorders
ããã·ã¥ãããã«æ¿å
¥ããŸãã// Order 6 cars
// - Increment "order" after each request
// - Add each order <K, V> pair to "orders" hash map
// - Call println! to show order details from the hash map
// Initialize order variable
let mut order = 1;
// Car order #1: Used, Hard top
car = car_factory(order, 1000);
orders.insert(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
...
// Car order #6: Used, Hard top
order = order + 1;
car = car_factory(order, 4000);
orders.insert(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
2. åé€ãããã¹ããŒãã¡ã³ããæ¬¡ã®ã³ãŒããããã¯ã«çœ®ãæããŸãã
// Start with zero miles
let mut miles = 0;
todo!("Add a loop expression to fulfill orders for 6 cars, initialize `order` variable to 1") {
// Call car_factory to fulfill order
// Add order <K, V> pair to "orders" hash map
// Call println! to show order details from the hash map
car = car_factory(order, miles);
orders.insert(order, car);
println!("Car order {}: {:?}", order, orders.get(&order));
// Reset miles for order variety
if miles == 2100 {
miles = 0;
} else {
miles = miles + 700;
}
}
3. ã¢ã¯ã·ã§ã³ãç¹°ãè¿ãã«ãŒãåŒã远å ããŠã6å°ã®è»ã®æ³šæãäœæããŸããorder
1ã«åæåããã倿°ãå¿
èŠã§ãã
4. ããã°ã©ã ããã«ãããŸããã³ãŒãããšã©ãŒãªãã§ã³ã³ãã€ã«ãããããšã確èªããŠãã ããã
次ã®äŸã®ãããªåºåã衚瀺ãããŸãã
Car order 1: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("New", 0) })
Car order 2: Some(Car { color: "Green", motor: SemiAuto, roof: false, age: ("Used", 700) })
Car order 3: Some(Car { color: "Red", motor: Automatic, roof: true, age: ("Used", 1400) })
Car order 4: Some(Car { color: "Silver", motor: SemiAuto, roof: false, age: ("Used", 2100) })
Car order 5: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("New", 0) })
Car order 6: Some(Car { color: "Green", motor: Automatic, roof: true, age: ("Used", 700) })
ããã°ã©ã ã¯çŸåšãã«ãŒãã䜿çšããŠ6å°ã®è»ã®æ³šæãåŠçããŠããŸãã6å°ä»¥äžæ³šæãããšã©ããªããŸããïŒ
main
颿°ã®ã«ãŒãåŒãæŽæ°ããŠã11å°ã®è»ã泚æããŸãã todo!("Update the loop expression to create 11 cars");
2. ããã°ã©ã ãåæ§ç¯ããŸããå®è¡æã«ãããã°ã©ã ã¯ãããã¯ã«ãªããŸãïŒ
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 1.26s
Running `target/debug/playground`
thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', src/main.rs:34:29
ãã®åé¡ã解決ããæ¹æ³ãèŠãŠã¿ãŸãããã
ãã®car_factory
颿°ã§ã¯ãif / elseåŒã䜿çšcolor
ããŠãcolors
é
åã®ã€ã³ããã¯ã¹ã®å€ã確èªããŸãã
// Prevent panic: Check color index for colors array, reset as needed
// Valid color = 1, 2, 3, or 4
// If color > 4, reduce color to valid index
let mut color = order as usize;
if color > 4 {
// color = 5 --> index 1, 6 --> 2, 7 --> 3, 8 --> 4
color = color - 4;
}
colors
é
åã«ã¯4ã€ã®èŠçŽ ãæã¡ããã€æå¹ãªcolor
å Žåã¯ãã€ã³ããã¯ã¹ã®ç¯å²ã¯0ã3ã®æ¡ä»¶åŒããã§ãã¯ããŠããcolor
ç§ãã¡ã¯ããã§ãã¯ããŸããïŒã€ã³ããã¯ã¹ã4ããã倧ããå Žåcolor
ããã®åŸã®é¢æ°ã§4ã«çããã€ã³ããã¯ã¹ãžã®ãšãã«æã
ã®ã€ã³ããã¯ã¹ãè»ã®è²ãå²ãåœãŠãé
åã§ã¯ãã€ã³ããã¯ã¹å€ãã1ãæžç®ããŸãcolor - 1
ãcolor
å€4ã¯colors[3]
ãé
åãšåæ§ã«åŠçãããŸããïŒ
çŸåšã®if / elseåŒã¯ã8å°ä»¥äžã®è»ã泚æãããšãã®å®è¡æã®ãããã¯ãé²ãããã«ããŸãæ©èœããŸãããããã11å°ã®è»ã泚æãããšãããã°ã©ã ã¯9çªç®ã®æ³šæã§ãããã¯ã«ãªããŸããããå ç¢ã«ãªãããã«åŒã調æŽããå¿ èŠããããŸãããã®æ¹åãè¡ãããã«ãå¥ã®ã«ãŒãåŒã䜿çšããŸãã
car_factory
æ©èœãã«ãŒãåŒã§ããã°/ä»ã®æ¡ä»¶æã亀æããŠãã ãããcolor
ã€ã³ããã¯ã¹å€ã4ãã倧ããå Žåã«å®è¡æã®ãããã¯ãé²ãããã«ãæ¬¡ã®æ¬äŒŒã³ãŒãã¹ããŒãã¡ã³ããä¿®æ£ããŠãã ããã// Prevent panic: Check color index, reset as needed
// If color = 1, 2, 3, or 4 - no change needed
// If color > 4, reduce to color to a valid index
let mut color = order as usize;
todo!("Replace `if/else` condition with a loop to prevent run-time panic for color > 4");
ãã³ã
ãã®å Žåãif / elseæ¡ä»¶ããã«ãŒãåŒãžã®å€æŽã¯å®éã«ã¯éåžžã«ç°¡åã§ãã
2. ããã°ã©ã ããã«ãããŸããã³ãŒãããšã©ãŒãªãã§ã³ã³ãã€ã«ãããããšã確èªããŠãã ããã
次ã®åºåã衚瀺ãããŸãã
Car order 1: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("New", 0) })
Car order 2: Some(Car { color: "Green", motor: SemiAuto, roof: false, age: ("Used", 700) })
Car order 3: Some(Car { color: "Red", motor: Automatic, roof: true, age: ("Used", 1400) })
Car order 4: Some(Car { color: "Silver", motor: SemiAuto, roof: false, age: ("Used", 2100) })
Car order 5: Some(Car { color: "Blue", motor: Manual, roof: true, age: ("New", 0) })
Car order 6: Some(Car { color: "Green", motor: Automatic, roof: true, age: ("Used", 700) })
Car order 7: Some(Car { color: "Red", motor: Manual, roof: true, age: ("Used", 1400) })
Car order 8: Some(Car { color: "Silver", motor: SemiAuto, roof: false, age: ("Used", 2100) })
Car order 9: Some(Car { color: "Blue", motor: Automatic, roof: true, age: ("New", 0) })
Car order 10: Some(Car { color: "Green", motor: SemiAuto, roof: false, age: ("Used", 700) })
Car order 11: Some(Car { color: "Red", motor: Manual, roof: true, age: ("Used", 1400) })
ãã®ã¢ãžã¥ãŒã«ã§ã¯ãRustã§äœ¿çšã§ããããŸããŸãªã«ãŒãåŒã調ã¹ãããã·ã¥ãããã®æäœæ¹æ³ãçºèŠããŸãããããŒã¿ã¯ãããŒãšå€ã®ãã¢ãšããŠããã·ã¥ãããã«ä¿åãããŸããããã·ã¥ãããã¯æ¡åŒµå¯èœã§ãã
loop
æåã§ããã»ã¹ã忢ãããŸã§ã®åŒã¯ãã¢ã¯ã·ã§ã³ãç¹°ãè¿ããŸããwhile
åŒãã«ãŒãããŠãæ¡ä»¶ãçã§ããéãã¢ã¯ã·ã§ã³ãç¹°ãè¿ãããšãã§ããŸãããã®for
åŒã¯ãããŒã¿åéãå埩åŠçããããã«äœ¿çšãããŸãã
ãã®æŒç¿ã§ã¯ãèªåè»ããã°ã©ã ãæ¡åŒµããŠãç¹°ãè¿ãããã¢ã¯ã·ã§ã³ãã«ãŒããããã¹ãŠã®æ³šæãåŠçããŸãããæ³šæã远跡ããããã«ããã·ã¥ããããå®è£ ããŸããã
ãã®ã©ãŒãã³ã°ãã¹ã®æ¬¡ã®ã¢ãžã¥ãŒã«ã§ã¯ãRustã³ãŒãã§ãšã©ãŒãšé害ãã©ã®ããã«åŠçããããã«ã€ããŠè©³ãã説æããŸãã
ãªã³ã¯: https://docs.microsoft.com/en-us/learn/modules/rust-loop-expressions/