Update: In addition to "Line"
, "Curve"
and "Doodle"
, we can use a number of built-in chart elements as the setting for "LegendItem"
:
Row[LineLegend[{Directive[Red, Dashed], Green, Blue, Orange},
{"A", "B", "C", "D"},
"LegendItem" -> #, LegendMarkerSize -> {30, 30}] & /@
{"Line", "Curve", "Doodle", "Square", "GlassRectangle", "ArrowRectangle",
"Bubble", "NoiseBubble", "OscillatingBubble",
"SquareWaveBubble", {Graphics@ Disk[],
Graphics@Text@Style["*", 64],
Graphics@Text@Style["\[FreakedSmiley]", 36],
ExampleData[{"TestImage", "Mandrill"}]}},
Spacer[10]]

Original answer:
u[x_] := x
sparkline = Plot[0, {x, 0, 1},
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], {x, 0, 1},
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]

An alternative ways is to use {sparkline}
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], {x, 0, 1},
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, {u}, "LegendItem" -> {sparkline}]]

Variations on the same idea:
colorfunctions = {"Rainbow", "SolarColors"};
functions = {Sin[x], Cos[x]};
sparklines = MapThread[Plot[#, {x, 0, 2 Pi},
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
{functions, colorfunctions}];
Show[MapThread[Plot[#, {x, 0, 2 Pi},
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, {TraditionalForm @ #},
"LegendItem" -> {#3}, LegendMarkerSize -> Large]] &,
{functions, colorfunctions, sparklines}]]
