Structured optical fields inside a waveguide possess the transverse spin, i.e., the spin angular momentum perpendicular to the direction of the waveguide. The physical origin of the transverse spin can be attributed to the presence of an effective rest mass of photons in guided waves, or equivalently, to the existence of a longitudinal field component, such that the transverse and longitudinal fields together form an elliptical polarization plane. In contrary to the traditional viewpoint, the transverse spin of photons in guided waves is also quantized, and its quantization form is related to the ellipticity of the polarization ellipse. The direction of the transverse spin depends on the propagation direction of electromagnetic waves along the waveguide, such a spin-momentum locking may have important applications in spin-dependent unidirectional optical interfaces. By means of a coupling between the transverse spin of guided waves and some physical degrees of freedom, one can develop an optical analogy of spintronics, i.e., spinoptics.